Computing.Net > Forums > Windows 2000 > Batchfile, Process part of filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batchfile, Process part of filename

Reply to Message Icon

Name: ikerstges
Date: May 18, 2005 at 04:22:50 Pacific
OS: Windows2000
CPU/Ram: PIII/256Mb
Comment:

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?!




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: May 18, 2005 at 07:35:05 Pacific
Reply:

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 EnableDelayedExpansion

Now 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.


0

Response Number 2
Name: ikerstges
Date: May 19, 2005 at 02:52:30 Pacific
Reply:

As always: BRILLIANT!

Many thanks Ivo!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Connect Solaris to window... W2K Reporting incorrect d...



Post Locked

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


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Batchfile, Process part of filename

parts of screen disappearing www.computing.net/answers/windows-2000/parts-of-screen-disappearing/62767.html

SET UP WIN2000 AS PART OF A DOMAIN www.computing.net/answers/windows-2000/set-up-win2000-as-part-of-a-domain/22422.html

STARTUP PROCESS www.computing.net/answers/windows-2000/startup-process/7034.html