1.

Solve : Copy file to an unknown folder name?

Answer»

I am trying to copy a file to another directory from a batch file but the problem I am having is that part of the directory path will change.

For example one of the folder names in the path will be 1w2e3.default and on another MACHINE it could be 1wed45.default. The folder name always has .default at the end so I need to know if there is some kind of wild card you can USE for the beginning of a folder name.

Any ideas?My guess is that you would need to know which machine the output is going to and then hardcode the output directory accordingly. Is there SOMEWAY you can distinguish one machine from another?

An easy trick is to put a zero byte file on each machine with a file label that will indicate which machine is which. Your batch file can then query the file label and determine which output directory is appropriate.

Good LUCK. 8-)chris_cs,

Piping the DIR command through FINDSTR and PARSING the output with the FOR command may help.
FINDSTR allows some kind of regular expression.


Code: [Select]set parentfolder=<foldername with *.default folder in it>
for /f "tokens=*" %%a in ('"dir /b "%parentfolder%"|findstr ".*\.default""') do set folder=%%~fa\
echo.%folder%DOS IT HELP? Tried the For statement and it worked like a dream!!!

Thanks for the help chris_cs,

Actually it can be simplified:

Code: [Select]set parentfolder=<foldername with *.default folder in it>
for /f "tokens=*" %%a in ('"dir /b *.default"') do set folder=%%~fa\
echo.%folder%



Discussion

No Comment Found