needs to get a filename in to a bat var

December 21, 2010 at 10:35:07
Specs: xp32, 555 phenom
I have a path x:\ in there I could have 1 to 4 files. I want to use them in a bat file but they are created in the bat file and not ready before hand. My target platform would be xp/vista. How can I get at minimum the first file found in to a var?

See More: needs to get a filename in to a bat var

Report •

December 21, 2010 at 10:55:06
If you are creating the file within the batch file, you would already have a name preset, right? Unless you are having the user enter a name manually, but then it would already be in a variable.

Or am I missing something? Show me your current code.

Can I put a question here?

Report •

December 21, 2010 at 11:02:10
well sort of. I do this.
"C:\Program Files\WinMount\winmount3" -m %1 -drv:x:\

the %1 is my in file name my out file name would be x:\file name.gcm Problem is my in file name is in quotes so I get this.

x:\"file name".gcm

from x:\%1.gcm

and also, the extraction may not match the name perfectly so its no good to me.

Report •

December 21, 2010 at 15:55:39
Try "x:\%~1.gcm"

The syntax %~1 expands %1 removing any quotes. But if it has any spaces, then you need the quotes to surround the whole pathname, otherwise they will be taken as separate parameters, "x:\file" and "name.gcm".

Report •

Related Solutions

December 28, 2010 at 20:22:24
well I did this

SET _test=%1
SET _result=%_test:"=% <--- there is a space here

and that replace my "'s with spaces. That worked, but I'd still like to have it take the first file in a directory or any file with a one in it?
can I use a regular exp some how?
x:\[ .*1 ].gcm

Report •

Ask Question