Computing.Net > Forums > Programming > Date Batch Script

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.

Date Batch Script

Reply to Message Icon

Name: djones
Date: May 10, 2007 at 16:53:14 Pacific
OS: WindowsXP
CPU/Ram: 1gig
Comment:

I need to automate an ftp file trasfer. Upon download of the file i need to add the date as a suffix to the filename i.e. text.txt becomes text051007.txt. i have the automate part figured out the problem is i dont know how to pass the name to the filename i think it involves something about passing that DATE futction to a variable at the command prompt in DOS but im pretty new to batch scripting and so im learning on the fly. If anyone could assist me in this matter it would be greatly appreciated.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 10, 2007 at 22:22:26 Pacific
Reply:

Where, exactly, are you stuck? Is the file name and date combined? Do you have the date formatted and ready to go? Do you need help with that?

Would something like this work?
1. Copy the last block of text.
2. Paste it in notepad.
4. Save it as "whatever.cmd" (NOT whatever.cmd.txt)
5. Run whatever.cmd "NameOfFileToBeChanged"

FOR /f "tokens=1-3 delims=/" %%a IN ('FOR /f "tokens=2" %%A IN ^("%DATE%"^) DO @ECHO %%A') DO REN "%~1" "%~n1%%c%%a%%b%~x1"


0

Response Number 2
Name: djones
Date: May 11, 2007 at 05:32:44 Pacific
Reply:

Razor 23 im going to try that code. I'm stuck at changing the name im just not sure how i would add the date as a suffix to the filename. and because everyday the date changes i wasnt sure how i would go about assigning the current date to a filename.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


0

Response Number 3
Name: Mechanix2Go
Date: May 11, 2007 at 06:16:04 Pacific
Reply:

The perennial problem is getting the date without second-guessing the layout/language/region etc.

This BAT will set date vars via BIOS.
::== YMD8.bat

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::== DONE


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: djones
Date: May 11, 2007 at 06:25:47 Pacific
Reply:

Mechanix so that script will pull the date from the bios correct? so after its run how would i go about adding the name to the filename. ie what.txt to what051107.txt the filename of the files never change which is why i need to add the date to the name once it is downloaded in order to maintain some order once they are archived.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


0

Response Number 5
Name: Mechanix2Go
Date: May 11, 2007 at 06:44:20 Pacific
Reply:

If you mean the file NAME doesn't change, use this:

ren myfile.ext myfile%year%%month%%dat%.ext


=====================================
If at first you don't succeed, you're about average.

M2



0

Related Posts

See More



Response Number 6
Name: djones
Date: May 11, 2007 at 07:21:04 Pacific
Reply:

Mechanix that last script was no good it doesn't add anything to the filename.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


0

Response Number 7
Name: Mechanix2Go
Date: May 11, 2007 at 07:31:49 Pacific
Reply:

Did you run YMD8.bat first? If you don't set the vars, nothing gets done.



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 8
Name: djones
Date: May 11, 2007 at 07:35:28 Pacific
Reply:

mechanix that syntax of ren new.txt new%year%%month%%dat%.txt actually worked the problem was that the date command couldnt read slashes ie 5/11/2006 so by changing it to %year-4,2% it worked.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


0

Response Number 9
Name: Mechanix2Go
Date: May 11, 2007 at 07:51:11 Pacific
Reply:

When I run ymd8 I get:

Date 11
Day Friday
Month 05
Year 2007
=============
When I run:

echo ren myfile.ext myfile%year%%month%%dat%.ext

I get:

ren myfile.ext myfile20070511.ext
======================
nothing to do with /



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 10
Name: djones
Date: May 11, 2007 at 08:06:31 Pacific
Reply:

mechanix your way absolutely correct your way and my way both worked. thanks alot for your help!

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Date Batch Script

batch script to parse filenames www.computing.net/answers/programming/batch-script-to-parse-filenames/15286.html

batch script www.computing.net/answers/programming/batch-script/14086.html

Batch script www.computing.net/answers/programming/batch-script-/14486.html