Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running batch files NT 4.0 vs Windows 2000

Status
Not open for further replies.

mukluk

MIS
Apr 14, 2005
4
US
Why does this script work perfectly on 2K and XP but not on NT 4.0?
Script:
set Day=%Date:~0,2%
set Mth=%Date:~3,2%
set Yr=%Date:~6,4%

ren d:\hamcount\arc_bu.zip arc_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\guardware_bu.zip guardware_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\master_bu.zip master_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\carriers.txt carriers%Day%-%Mth%-%Yr%.txt

move /Y d:\hamcount\*.* d:\hamcount\archive

ERRORS:
C:\>hammove1.bat

C:\>set Day=:~0,2

C:\>set Mth=:~3,2

C:\>set Yr=:~6,4

C:\>ren c:\hamcount\arc_bu.zip arc_bu:~0,2-:~3,2-:~5,4.zip
The syntax of the command is incorrect.

C:\>ren c:\hamcount\guardware_bu.zip guardware_bu:~0,2-:~3,2-:~5,4.zip
The syntax of the command is incorrect.

C:\>ren c:\hamcount\master_bu.zip master_bu:~0,2-:~3,2-:~5,4.zip
The syntax of the command is incorrect.

C:\>ren c:\hamcount\carriers.txt carriers:~0,2-:~3,2-:~5,4.txt
The syntax of the command is incorrect.

C:\>move /Y c:\hamcount\*.* c:\hamcount\archive
The syntax of the command is incorrect.

C:\>
 
I tried it on my Windows XP machine, and got this:

C:\>ren c:\hamcount\arc_bu.zip arc_bu:~0,2-:~3,2-:~5,4.zip
The syntax of the command is incorrect.

When I removed the colons and commas it finished successfully:

C:\>ren c:\hamcount\arc_bu.zip arc_bu~02-~32-~54.zip

C:\>dir C:\hamcount
Volume in drive C is System
Volume Serial Number is 200D-B953

Directory of C:\hamcount

04/28/2005 02:16 PM <DIR> .
04/28/2005 02:16 PM <DIR> ..
04/28/2005 02:13 PM 6 arc_bu~02-~32-~54.zip
1 File(s) 6 bytes
2 Dir(s) 11,888,099,328 bytes free
 
Serbtastis, thanks. But,

I want to keep the new daily files in the same directory. I will have Task Scheduler fire this thing off at 2 AM every day after the new files are dumped.

The goal if this script is to insert the current date into the file name. So the desired results would be like this.

arc_bu-05-03-05.zip
arc_bu-05-04-05.zip
arc_bu-05-05-05.zip
arc_bu-05-06-05.zip ...etc

Looks like NT doesn't mind setting the variables here;
set Day=%Date:~0,2%
set Mth=%Date:~3,2%
set Yr=%Date:~6,4%

Any other ideas why NT doesn't like these lines?

ren d:\hamcount\arc_bu.zip arc_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\guardware_bu.zip Guardware_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\master_bu.zip master_bu%Day%-%Mth%-%Yr%.zip
ren d:\hamcount\carriers.txt carriers%Day%-%Mth%-%Yr%.txt
 
I was able to get it to run successfully on my WinXP machine by defining the variables thusly:

set Day=%DATE:~7,2%
set Mth=%DATE:~4,2%
set Yr=%DATE:~12,2%

Post the output of the following command on your Windows NT machine (I don't have one I can test with) and I'll try to help you out:

echo %DATE%
 
Here you go...

C:\>echo %DATE%
%DATE%

Thx.
 
Yup, just as I confirmed on a test NT box here, there is no var named DATE on Windows NT. That's your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top