Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi list..
I try to create a batchfile to process files, based on the content of their file-names.
Example filename: Packlist_20050518_12345.html
There will be more than 1 filenames in the directory for processing. I need "2005" and "05" and "18" to be stored in a separate variable. After processing, the files can move to a different folder.
I think I need to adjust the for-do statement:
For /F "tokens=_" %%A in ('Dir /B /A:-D %1') Do (This statement uses the "_" character as the separator and thus, I get "Packlist" and "20050518" and "12345" in separate variables, but how do I cut the resulting "20050518" into their own variables???
Any help will be greatly appreciated?!

First of all you need to enable the Delayed Expansion of variables to process them inside a code block held by the For statement. So start your batch coding
@Echo Off
SetLocal EnableDelayedExpansionNow you can use the following For according to your file names format
For /F "tokens=1,2,3 delims=_" %%A in ('Dir /B /A:-D %1') Do (
Set FileName=%%A_%%B_%%C
Set FileDate=%%B
Set FileYY=!FileDate:~0,4!
Set FileMM=!FileDate:~4,2!
Set FileDD=!FileDate:~6,2!
Call :EXEC)
.....
.....
EndLocal
GoTo :EOF:EXEC
[your subroutine to process filenames]
GoTo :EOF:EOF is the standard return point for NT main/subroutines and does not need to be delared.

![]() |
Connect Solaris to window...
|
W2K Reporting incorrect d...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |