Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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"

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

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 Qdebug < d.d > nul
del d.ddat
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

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

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

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

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

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

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

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

![]() |
![]() |
![]() |

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