Help is desperately needed

D

Dwane

I am trying to create a DOS batch that would allow me to compare
today's date with a filename ddmmyyyy-xxxx-xxxx-na.txt. The "a" in the

"na" is also significant in that it designates an add process and a "d"

would therefore signify to delete.

I first need to compare the current date with the first 8 letters of my

filename and if they are equal, I need to execute a command, then
rename the file to X-ddmmyyyy-xxxx-xxxx-na.txt.


Does anyone have an idea of how I can do this? I have been looking all

over the web and am not sure exactly how to do string manipulation. I
even looked to see if there was a way to copy the filename into a file
and then manipulate data there or even copy the directory into a list
and do it there.


Any help would be appreciated.


Thank you
 
M

Mark V

In said:
I am trying to create a DOS batch that would allow me to compare
today's date with a filename ddmmyyyy-xxxx-xxxx-na.txt. The "a"
[ ]

Multi-Post (alt.msdos.batch.nt)
 
B

billious

Dwane said:
I am trying to create a DOS batch that would allow me to compare
today's date with a filename ddmmyyyy-xxxx-xxxx-na.txt. The "a" in the

"na" is also significant in that it designates an add process and a "d"

would therefore signify to delete.

I first need to compare the current date with the first 8 letters of my

filename and if they are equal, I need to execute a command, then
rename the file to X-ddmmyyyy-xxxx-xxxx-na.txt.


Does anyone have an idea of how I can do this? I have been looking all

over the web and am not sure exactly how to do string manipulation. I
even looked to see if there was a way to copy the filename into a file
and then manipulate data there or even copy the directory into a list
and do it there.


Any help would be appreciated.


Thank you

Please make your subject headers more meaningful. Many people won't respond
if you state the obvious. You're unlikely to be posting a question if you
don't want help.

Try the following. You don't tell us your date format, so we have to guess.
You also don't tell us your OS. This was constructed and tested in XP.

[1]@echo off
[2]:: get current date to a variable
[3]:: don't know your format. Mine is 09/08/2006 for Aug 9th
[4]:: so mine use the 2 characters from "character 0" (09)
[5]:: strung with the two from "character 3" (08)
[6]:: and then with the four from "character 6"
[7]set ycd=%date:~0,2%%date:~3,2%%date:~6,4%
[8]::
[9]:: scan all files of the format date-????-????-n?.txt
[10]::
[11]for /f %%i in ( ' dir /b/a-d d:\somedir\%ycd%-????-????-n?.txt ' ) do
call :process %%i
[12]:: clean up environment
[13]for %%i in (ycd tfn) do set %%i=
[14]goto :eof
[15]
[16]:process
[17]:: Just informational....
[18]ECHO processing %1
[19]:: filename + path to a variable
[20]set yfn=d:\somedir\%1
[21]if /i %yfn:~-5,1%==a echo a-process %1&goto newname
[22]if /i %yfn:~-5,1%==d echo d-process %1&goto newname
[23]echo %1 not processed
[24]goto :eof
[25]
[26]:newname
[27]echo ren %yfn% X-%1
[28]
[29]goto :eof

lines begin [number] for identification and reference. Any line not
beginning [number] is being shown wrapped and needs to be rejoined. The
[number] needs to be removed.

As it stands, the batch will simply REPORT what it intends to do.

d:\somedir\ should be replaced by your pathname to the appropriate directory

Change the "echo x-process" from lines [21],[22] to CALL BATCHFILENAME if
your processing is a batchfile, or PROGRAMNAME if your processing is
performed by a program. change the %1 to %yfn% if you need the path as well
as the filename.

delete the ECHO keyword from line [27] to actually perform the rename.

Intensive batch-techniques discussion in alt.msdos.batch.nt
 
D

Dwane

billious said:
Dwane said:
I am trying to create a DOS batch that would allow me to compare
today's date with a filename ddmmyyyy-xxxx-xxxx-na.txt. The "a" in the

"na" is also significant in that it designates an add process and a "d"

would therefore signify to delete.

I first need to compare the current date with the first 8 letters of my

filename and if they are equal, I need to execute a command, then
rename the file to X-ddmmyyyy-xxxx-xxxx-na.txt.


Does anyone have an idea of how I can do this? I have been looking all

over the web and am not sure exactly how to do string manipulation. I
even looked to see if there was a way to copy the filename into a file
and then manipulate data there or even copy the directory into a list
and do it there.


Any help would be appreciated.


Thank you

Please make your subject headers more meaningful. Many people won't respond
if you state the obvious. You're unlikely to be posting a question if you
don't want help.

Try the following. You don't tell us your date format, so we have to guess.
You also don't tell us your OS. This was constructed and tested in XP.

[1]@echo off
[2]:: get current date to a variable
[3]:: don't know your format. Mine is 09/08/2006 for Aug 9th
[4]:: so mine use the 2 characters from "character 0" (09)
[5]:: strung with the two from "character 3" (08)
[6]:: and then with the four from "character 6"
[7]set ycd=%date:~0,2%%date:~3,2%%date:~6,4%
[8]::
[9]:: scan all files of the format date-????-????-n?.txt
[10]::
[11]for /f %%i in ( ' dir /b/a-d d:\somedir\%ycd%-????-????-n?.txt ' ) do
call :process %%i
[12]:: clean up environment
[13]for %%i in (ycd tfn) do set %%i=
[14]goto :eof
[15]
[16]:process
[17]:: Just informational....
[18]ECHO processing %1
[19]:: filename + path to a variable
[20]set yfn=d:\somedir\%1
[21]if /i %yfn:~-5,1%==a echo a-process %1&goto newname
[22]if /i %yfn:~-5,1%==d echo d-process %1&goto newname
[23]echo %1 not processed
[24]goto :eof
[25]
[26]:newname
[27]echo ren %yfn% X-%1
[28]
[29]goto :eof

lines begin [number] for identification and reference. Any line not
beginning [number] is being shown wrapped and needs to be rejoined. The
[number] needs to be removed.

As it stands, the batch will simply REPORT what it intends to do.

d:\somedir\ should be replaced by your pathname to the appropriate directory

Change the "echo x-process" from lines [21],[22] to CALL BATCHFILENAME if
your processing is a batchfile, or PROGRAMNAME if your processing is
performed by a program. change the %1 to %yfn% if you need the path as well
as the filename.

delete the ECHO keyword from line [27] to actually perform the rename.

Intensive batch-techniques discussion in alt.msdos.batch.nt

I appreciate the advice. My O/S is Windows 2000. I was trying to use
the current time of the system to compare with the file.

Thank you
 
F

foxidrive

I appreciate the advice. My O/S is Windows 2000. I was trying to use
the current time of the system to compare with the file.

Thank you

Did the solution work for you?
 
D

Dwane

billious said:
Dwane said:
I am trying to create a DOS batch that would allow me to compare
today's date with a filename ddmmyyyy-xxxx-xxxx-na.txt. The "a" in the

"na" is also significant in that it designates an add process and a "d"

would therefore signify to delete.

I first need to compare the current date with the first 8 letters of my

filename and if they are equal, I need to execute a command, then
rename the file to X-ddmmyyyy-xxxx-xxxx-na.txt.


Does anyone have an idea of how I can do this? I have been looking all

over the web and am not sure exactly how to do string manipulation. I
even looked to see if there was a way to copy the filename into a file
and then manipulate data there or even copy the directory into a list
and do it there.


Any help would be appreciated.


Thank you

Please make your subject headers more meaningful. Many people won't respond
if you state the obvious. You're unlikely to be posting a question if you
don't want help.

Try the following. You don't tell us your date format, so we have to guess.
You also don't tell us your OS. This was constructed and tested in XP.

[1]@echo off
[2]:: get current date to a variable
[3]:: don't know your format. Mine is 09/08/2006 for Aug 9th
[4]:: so mine use the 2 characters from "character 0" (09)
[5]:: strung with the two from "character 3" (08)
[6]:: and then with the four from "character 6"
[7]set ycd=%date:~0,2%%date:~3,2%%date:~6,4%
[8]::
[9]:: scan all files of the format date-????-????-n?.txt
[10]::
[11]for /f %%i in ( ' dir /b/a-d d:\somedir\%ycd%-????-????-n?.txt ' ) do
call :process %%i
[12]:: clean up environment
[13]for %%i in (ycd tfn) do set %%i=
[14]goto :eof
[15]
[16]:process
[17]:: Just informational....
[18]ECHO processing %1
[19]:: filename + path to a variable
[20]set yfn=d:\somedir\%1
[21]if /i %yfn:~-5,1%==a echo a-process %1&goto newname
[22]if /i %yfn:~-5,1%==d echo d-process %1&goto newname
[23]echo %1 not processed
[24]goto :eof
[25]
[26]:newname
[27]echo ren %yfn% X-%1
[28]
[29]goto :eof

lines begin [number] for identification and reference. Any line not
beginning [number] is being shown wrapped and needs to be rejoined. The
[number] needs to be removed.

As it stands, the batch will simply REPORT what it intends to do.

d:\somedir\ should be replaced by your pathname to the appropriate directory

Change the "echo x-process" from lines [21],[22] to CALL BATCHFILENAME if
your processing is a batchfile, or PROGRAMNAME if your processing is
performed by a program. change the %1 to %yfn% if you need the path as well
as the filename.

delete the ECHO keyword from line [27] to actually perform the rename.

Intensive batch-techniques discussion in alt.msdos.batch.nt

My apologies, I got busy with another project. Please let me try this
and I will get back with you tomorrow.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top