storing command output in a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rmukherjee
Posts: 2
Joined: 23 Nov 2008 01:06
Location: India

storing command output in a variable

#1 Post by rmukherjee » 23 Nov 2008 01:28

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?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 23 Nov 2008 01:44

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:

rmukherjee
Posts: 2
Joined: 23 Nov 2008 01:06
Location: India

#3 Post by rmukherjee » 23 Nov 2008 01:54

:D You are a life saver man !!!!

Post Reply