Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Operating System (http://www.go4expert.com/forums/operating-system-forum/)
-   -   Using batch file to open multiple text files using Notepad simultaneously (http://www.go4expert.com/forums/using-batch-file-multiple-text-files-t18303/)

terrylau 2Jul2009 14:19

Using batch file to open multiple text files using Notepad simultaneously
 
Not sure whether it's relevant here but here goes...

I want to open multiple text files in a folder using Notepad, all at the same time. Using command line window

Start ->Run -> Cmd
cd C:\Test
for %X in (*.txt) do notepad %X

will enable all the files open on top of one another.


I want to create a batch file to automate this process but by doing :

cmd
for %%X in ("C:\Test\"*.txt) do notepad %%X

will only open the first file File1.txt. After closing File1.txt, then only the second file File2.txt will open and so on.

Is there a way for me to automate this process using batch file or any other programming language that'll be more suitable e.g. VB, Perl, C/C++, etc.

Need your input and suggestions as still new to programming. Thanks.

SaswatPadhi 2Jul2009 17:01

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Hi and welcome to G4EF :)

So, you want all txt files to be open simultaneously, right ?

This is an easy task and can be done in any language. But I will prefer VBScript as you need not compile it and you can directly run it like a batch file. :)

Code: VB

Dim objFSO
Dim MyFile
Dim MyFolder
Dim objShell

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = objFSO.GetFolder("C:\Test")
Set objShell = WScript.CreateObject("WScript.Shell")

For Each MyFile In MyFolder.Files
    If Right(MyFile.Path,4) = ".txt" Then
        objShell.Run("notepad " + MyFile.Path)
    End If
Next

Copy the code above, paste it in notepad and save the file as "Test.vbs". Run it .. it will work :)

The code is quite self explanatory, so you won't have difficulty understanding it. If you need to change the target folder, change the variable MyFolder.

terrylau 3Jul2009 07:38

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Thanks for the welcome. You've got exactly what I need!!! :) Thanks again.

SaswatPadhi 3Jul2009 12:08

Re: Using batch file to open multiple text files using Notepad simultaneously
 
My pleasure ! :)

RandiR 20Aug2009 19:34

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Nice solution. Nice forum. Here is an alternate script to open all .txt files in C:\Test one by one with notepad.

Code:


# Script txtfiles.txt
cd "C:\Test" ; var str list ; lf -n "*.txt" > $list
while ($list <> "")
do
    var str file ; lex "1" $list > $file ; system ("\""+$file+"\"")
done

The script is in biterscripting ( biterscripting.com ) . You can flex the lf command to do different things.

lf -rn "*.txt"
Find files recursively in subfolders and subsubfolders.

lf -rn "*.txt" "C:\folder"
Find files in C:\folder".

lf -rn "*.txt" "C:\folder" ($fsize > 5000)
Find files whose size is greater than 5000 bytes.

lf -rn "*.txt" "C:\folder" ( ($fsize > 5000) AND ($fctime > "20090101") )
Find files whose size is greater than 5000 bytes AND whose creation time is after Jan 1, 2009.

etc.


Randi

terrylau 21Aug2009 05:32

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Wow.. nice... thanks..

Btw, that looks like Perl scripting isit?

SaswatPadhi 21Aug2009 06:06

Re: Using batch file to open multiple text files using Notepad simultaneously
 
That's bitterScripting, as he mentioned.

naimish 21Aug2009 08:31

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Nice code SP ;) in VB....I would like to implement same in .NET ;)

topsy99 4Oct2009 07:19

Re: Using batch file to open multiple text files using Notepad simultaneously
 
i tried this vbs file to open multiple text files and get programming error on line 7 character 6 expected '='

what does this mean

SaswatPadhi 4Oct2009 18:50

Re: Using batch file to open multiple text files using Notepad simultaneously
 
Quote:

Originally Posted by topsy99 (Post 58365)
i tried this vbs file to open multiple text files and get programming error on line 7 character 6 expected '='

what does this mean

The VBS file that I have posted works perfectly fine.
Which VBS file are you referring to ? Could you (re-)post it here ?


All times are GMT +5.5. The time now is 19:53.