Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My goal is to create a batch file that will extract the contents of a zip file to a separate directory. Every file related to this question is on the same flash drive.

The following command works just fine with the drive letter i:\

**i:\7z x i:\zips\ -oi:\apps\new_app**

What happens if I put the flash drive into a different computer and the drive letter is NOT i:\ but f:\ or g:\ or q:\

Is there some sort of variable I can create?

share|improve this question
up vote 2 down vote accepted

Replace I:\ with %CD%. The %CD% environmental variable holds the current directory path.

%CD%\7z x %CD%\zips\ -o%CD%\apps\new_app

Upon double-clicking the batch file, it starts in the directory it resides in. If the batch file is in the root of the USB stick, %CD% will be set to I:\ or whatever drive letter the USB stick got mounted as.

share|improve this answer
Perfect. For others I will add that I didn't need the / after the % – user216384 Apr 12 '13 at 4:11

If you run the .BAT file from the USB drive you don't need to specify the drive letter, only the path and/or file relative to the .BAT file.

Example: If Unzip.BAT is in the root of the USB Drive and the .zip is in a folder called "classified docs" under a folder called "secret" it would be

\secret\classified docs\
share|improve this answer
I can't get the command version of 7zip to accept that though. When I use the -o it wants a drive letter after it.....unless I'm doing it wrong....which could also be true. – user216384 Apr 12 '13 at 3:55
Ahh, that could be problematic. I don't know enough about 7zip to make any further suggestions. I think Rain there has the answer though as that should work. – Martin Toy Apr 12 '13 at 3:59

This design can be used from within the folder structure:

"%cd:~0,2%\<full path>"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.