|
Answer» Hello,
I'm tyring to run the command below to output filenames with a specific format to a text file. The script outputs a directory listing to a text file, it then does a dir listing on any subdirectories and finally it does a dir listing of files in those directories. We then output the VARIABLES returned to a text file to create a unique filename based on the directory listings. The issue I'm having is that I want to subtitute a variable for the top directory name RATHER than using the directory name itself.
Any ideas would be MUCH appreciated.
Example filename required - 130042008filename.tif from the variables - echo %var%%%b%%c
Current Filename returned - Directory name A30042008filename.tif from the variables echo %%a%%b%%c
del c:\filenames.txt dir /b E:\ > c:\dir.txt for /f "tokens=*" %%a in ( 'type c:\dir.txt' ) do ( echo %%a if %%a == Directory name A ( set var=1 echo %var% dir /b "e:\%%a\Images\*" > c:\dates.txt for /f "tokens=*" %%b in ( 'type c:\dates.txt' ) do ( echo %%b for /f "tokens=*" %%c in ( 'dir /b "e:\%%a\Images\%%b\*"' ) do ( echo %var% echo %%c echo %var%%%b%%c >> c:\files2.txt ))
if %%a == Directory name B ( set var=2 echo %var% dir /b "e:\%%a\Images\*" > c:\dates.txt for /f "tokens=*" %%b in ( 'type c:\dates.txt' ) do ( echo %%b for /f "tokens=*" %%c in ( 'dir /b "e:\%%a\Images\%%b\*"' ) do ( echo %var% echo %%c echo %var%%%b%%c >> c:\files2.txt ))
) )You could try parsing the path using the backslash as a DELIMITER. This would break down the path into component parts which you can glue back together using just the drive and the top level directory.
Good luck.
|