VBS - Open Files

Soldato
Joined
17 Sep 2005
Posts
2,983
Location
Everywhere
Hiyo,

Trying to create a VB Script that will ask you for a folder path and then open all the files in that folder with Notepad. I don't want to have to keep editing the VBS file to put the path in.

At the moment I have this, but I can't figure out how to implement the InputBox command. Any help appreciated!

Code:
Dim objFSO
Dim MyFile
Dim MyFolder
Dim objShell

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

Set MyFolder = objFSO.GetFolder("W:\Folder")

For Each MyFile In MyFolder.Files    
        objShell.Run("notepad " + MyFile.Path)
  
Next

Thanks
 
You can use WScript.Arguments.Item(n) to get the command line parameters passed to your script, more info here

So, for example, you'd open your script with:

Code:
> myScript.vbs "C:\Folder\SubFolder"

And you'd deal with this by using:

Code:
folderLoc = WScript.Arguments.Item(0)
Set MyFolder = objFSO.GetFolder(folderLoc)

You'd obviously need some form of validation if no/more than 1 parameter is provided.
 
Last edited:
Is there a way, if I add a Right Click context menu option, whereby if I right click on one of the folders, and there is a option to open all files within that folder with notepad.
 
With Notepad ++ you can select all the files in a folder with Ctrl-A and then right click --> Edit in Notepad ++. This does the trick for me anyway and opens them in Notepad ++ with a seperate tab for each file.

I don't see how having to select the folder from a prompt is any less work than this really!
 
With notepad++ you can also right-click a folder and open all files from inside it, if you put a shortcut to notepad++ in your Send To folder (e.g. in c:\users\topdog\appdata\roaming\microsoft\windows\sendto\ ).

That trick won't work with notepad because it tries to open the folder itself, np++ is a bit smarter in this regard.
 
Thanks for your responses. Basically, I have a Folder Structure with hundreds and hundreds of folders all with files which have been archived with Permabit. In order to retrieve, the files need to be opened, so I want a script which scans the whole Job Folder and opens up every single file which has been archived.
 
Back
Top Bottom