1.

Solve : Need Help reading a date?

Answer»

Hi,
I need to FTP a file each day. The file comes from another program with today's date in the name. I can't change the name of the file so I need a way to have the name change each day in the batch file.

So lets say todays file is

06172010bob.txt
The next day is
06182010bob.txt

Any ideas on how to change the name in the script to add todays file name when FTP'n?

Thanks

This question, in one form or another has been asked and answered numerous times. If you are in a rush, you might save time by doing a forum search.

In the meantime we need to know the format of your system date. Please run
echo %date% from the COMMAND prompt window and post the result along with your batch file.

 Sorry if this has been covered. I think I over looked it.

My machine date is like this....

Fri 06/18/2010

The file I am FTP'n is named 20100618ABCD.txt

If the name was static I would be all set to send the files but with the change of the date each day I have to edit my batch to change the file name to the date.

Thanks for your help
Your posts are contradictory. One shows the dates in the file names as mmddyyyy and the other shows the file names as yyyymmdd.

This snippet is for the mmddyyyy format:
Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "tokens=2" %%v in ("%date%") do (
  set today=%%v
  set today=!today:/=!


echo %today%

This snippet is for the yyyymmdd format:
Code: [Select]echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
  set today=%%l%%j%%k
)

echo %today% 

Choose which snippet meets your needs. The today variable is set to the current date. You didn't post your batch file so I can't assist there but there may be problems with the FTP environment "seeing" the cmd shell environment variables.

Good luck.  Thank you.

What I am using for the batch file is really 2 files. The first is a batch file and the 2nd is a text file.

Xfer.bat
ftp -n -s:E:\ctftp\dataxfer.txt xxx.xxx.xxx.xxx
PAUSE



dataxfer.txt

user USERNAME password
put E:\ctftp\20100618ABCD.txt
rename 20100618ABCD.txt ack
bye

I need to see the text of the transfer and found this does it for me.

Thanks again!
Quote

Choose which snippet meets your needs. The today variable is set to the current date. You didn't post your batch file so I can't assist there but there may be problems with the FTP environment "seeing" the cmd shell environment variables.

Can you give me a hand with this? I posted what I am using now but it sounds like you have a better way to do things.

Thanks
Quote from: Spoiler on June 21, 2010, 12:06:25 PM
Can you give me a hand with this? I posted what I am using now but it sounds like you have a better way to do things.

Thanks


You give me way too much credit. If what you're are using works, then it's a success story. An alternative way would be to create the dataxfer.txt file on the fly.

Code: [Select]echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
  set today=%%l%%j%%k
)

>  E:\ctftp\dataxfer.txt echo username password
>> E:\ctftp\dataxfer.txt echo put E:\ctftp\%today%ABCD.txt
>> E:\ctftp\dataxfer.txt echo ren E:\ctftp\%today%ABCD.txt ack
>> E:\ctftp\dataxfer.txt echo bye

ftp -n -s:E:\ctftp\dataxfer.txt xxx.xxx.xxx.xxx
del E:\ctftp\dataxfer.txt
pause

I couldn't determine if the ABCD part of the file name was static or CHANGED from day to day. The snippet may need further tweaks.

Good luck.  Howdy,

Thanks I will give it a try and see if it works out ok. The ABCD.TXT part of the file name stays the same. The only part of the file name that changes is the date.

Thanks again.

Quote
>  E:\ctftp\dataxfer.txt echo username password

I had to make a small change so it read echo user username password

Things work great now. Thanks again for your help!



Discussion

No Comment Found