Page 1 of 1

storing command output in a variable

Posted: 23 Nov 2008 01:28
by rmukherjee
I will be receiving a file from a different system and will process it. However the filename is dynamic.

INFILE_IETPAT_V_NNNNNN_NNN.CSV ( Where N is a numeric value )

I need the actual filename for processing it. Please note at a time only one file will be present inside VDMT folder.

I have written following piece of code-

set filename=%dir/b C:\VDMT\INFILE_IETPAT_V*%

however the output of dir command is not being stored rather the whole %dir/b .....% string is being stored.

Can anyone please throw some light?

Posted: 23 Nov 2008 01:44
by DosItHelp
rmukherjee,

You could try:

Code: Select all

For %%A in ("C:\VDMT\INFILE_IETPAT_V*") do set "filename=%%A"

Or:

Code: Select all

For "delims=" %%A in ('"dir /b "C:\VDMT\INFILE_IETPAT_V*%""') do set "filename=%%A"

DosItHelp? :wink:

Posted: 23 Nov 2008 01:54
by rmukherjee
:D You are a life saver man !!!!