Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Open Folders from Command Prompt .bat file

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 1 posts
I have a drive "R:\" with a ton of job files in it all organized by job number.

What I want to do is create a .bat file that will open a dos window and simply let me type in the job number (ie "1302-0059"), press enter, and that will open the proper job folder in Windows Explorer (and close the dos window as well).

Yes, I know I'm lazy because I can just use "Run" and type R:\######## every time, but that R:\ is a pain....and its also annoying to have to highlight just the job numbers as well...ya I know, lazy.

Am I on the right track here? Any help with code? Never done something like this before...Running Windows 7 btw.

Thanks for any help!
  • 0




    Trusted Helper

  • Malware Removal
  • 4,889 posts

In my opinion its easy to do it in vbscript, adjust as you need...

dim WSh: set WSh = WScript.createObject("WScript.Shell")
Dim sJob

sJob = InputBox("Enter Job reference:", "Open Job Folder")
If sJob <> "" Then
  Wsh.Run "%comspec% /c start " & "R:\" & sJob
End If 

Edited by SleepyDude, 01 May 2013 - 04:28 PM.

  • 0




  • Member
  • PipPipPipPip
  • 1,355 posts
Hey there HardAtWork and welcome to GeeksToGo,

Well as mentioned above, you may use the script in order to do what you require... Although you are trying to write a batch file (Which would probably be much easier), a batch file is easy enough to write and understand so I'll pop what should go into the contents of the batch file below with brief explanations:

> Firstly you will have to open notepad (Notepad is a basic text editor which will be more than sufficient for writing your batch code in)
> Then copy and paste the code provided below:

@echo off
SET /P folder="Please Enter Folder Name: "
explorer "R:\%folder%\"
The first line "@echo off" is just a key line that will tell the command window that you do not want to output any content of your batch file unless explicitly specified.
The second line is where you ask the user (Yourself in this case) to enter in some form of value and then store that value into a variable. In this case the variable is "folder".
The last line is a call to the "explorer.exe" that takes a command line argument of the folder you would like to navigate to upon opening. As you can see the folder is replaced by the variable created earlier from the users input.

For the scope of what it seems you require I have not gone in-depth in my explanations (Of course if you require further explanation do not hesitate to ask). Also if you were to enter a folder that doesn't exist, explorer would just open to the default folder (Usually Documents).

Peace Out :cool:
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP