Using output characters as input in a batch

October 15, 2010 at 18:49:54
Specs: Windows 7
Hello everyone, I have been looking around for an easier way to run a batch file from a flash drive without having to enter the filename.bat <drive letter> and using the "%1" in the path in the batch. I think I may have come up with something but I'm not sure if it's possible. I'm very new to batch files so if it's not possible I understand.

If I run the "vol" command in a batch file from the flash drive I get:
Volume in drive H is Lexar
Volume Serial Number is 9986-D45F

Is there a way to take the 18th character (H in this case) and use that later in the batch file when referencing the path of the file I want to ultimately copy? If i run a cls before I run the vol command the output SHOULD always be in the same location on the screen if that even matters.

I hope that made sense.

Thanks for any help!

See More: Using output characters as input in a batch

Report •

October 15, 2010 at 20:07:27
[1] Win7 is not DOS. Not even close.

[2] In Win7 and other NT systems:

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('CD') do (
set DLTR=%%a & set DLTR=!DLTR:~0,1!

Life is too important to be taken seriously.


Report •

October 15, 2010 at 21:20:32
Sorry about that. I should have looked around a little more before I posted. Thanks for the quick response! I'll give it a shot.

Report •

October 16, 2010 at 05:14:56
Alternatively (assuming this script runs from the USB drive):
echo %~d0

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question