Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Open Folders from Command Prompt .bat file


  • Please log in to reply

#1
HardAtWork

HardAtWork

    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

Advertisements


#2
SleepyDude

SleepyDude

    Trusted Helper

  • Malware Removal
  • 4,976 posts
Hi,

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

#3
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 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