Using batch file to open multiple text files using Notepad simultaneously

terrylau's Avatar, Join Date: Jul 2009
Go4Expert Member
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.
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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.
0
terrylau's Avatar, Join Date: Jul 2009
Go4Expert Member
Thanks for the welcome. You've got exactly what I need!!! Thanks again.
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
My pleasure !
0
RandiR's Avatar, Join Date: Mar 2009
Light Poster
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
SaswatPadhi like this
0
terrylau's Avatar, Join Date: Jul 2009
Go4Expert Member
Wow.. nice... thanks..

Btw, that looks like Perl scripting isit?
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
That's bitterScripting, as he mentioned.
0
naimish's Avatar
Banned
Nice code SP in VB....I would like to implement same in .NET
0
topsy99's Avatar
Go4Expert Member
i tried this vbs file to open multiple text files and get programming error on line 7 character 6 expected '='

what does this mean
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Quote:
Originally Posted by topsy99 View Post
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 ?