We are currently converting schedulers. Currently I am able to do file transfers using Wildcards, and then in a post process, I can get what was moved and read it to get the filename for the file that was moved with the wildcard. We are not able to do this anymore with the new scheduler of getting the name from the post process.

The folder should have only 1 file after the transfer with that name, so for example the folder "C:\Files\" could have:

Document 1079475.pdf

If I am wanting to get the filename "Document 1079475.pdf" from the list and put that into a variable how would you do it with batch scripting in Windows knowing just "Document*.pdf"?

I have tried the commands below:

dir "%homedrive%\Files\Document*.pdf" > temp.txt
set /p VAR=<temp.txt
echo %VAR%

However, running the first line returns to the file:

 Volume in drive C is OSDisk
 Volume Serial Number is D841-0924

 Directory of C:\Files
 08/01/2016  10:05 PM           128,657 Document 1079475.pdf
               1 File(s)        128,657 bytes
               0 Dir(s)  63,461,928,960 bytes free

So the variable VAR returns

Volume in drive C is OSDisk

If you're doing specific searches and you do dir without headers and for files only like:

dir /b /A:A "%homedrive%\Files\Document*.pdf" > temp.txt

The same command you tried will work and give you just the filename (and a newline).

dir /? 

will give you other options which may be helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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