

InterviewSolution
Saved Bookmarks
1. |
Solve : Need Help reading a date? |
Answer» <html><body><p>Hi,<br/>I need to <a href="https://interviewquestions.tuteehub.com/tag/ftp-20066" style="font-weight:bold;" target="_blank" title="Click to know more about FTP">FTP</a> 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. <br/><br/>So lets say todays file is <br/><br/>06172010bob.txt<br/>The next day is<br/>06182010bob.txt<br/><br/>Any ideas on how to change the name in the script to add todays file name when FTP'n?<br/><br/>Thanks<br/><br/>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.<br/><br/>In the meantime we need to know the format of your system date. Please run<br/><strong>echo %date%</strong> from the <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a> prompt window and post the result along with your batch file. <br/><br/> Sorry if this has been covered. I think I over looked it.<br/><br/>My machine date is like this....<br/><br/>Fri 06/18/2010<br/><br/>The file I am FTP'n is named 20100618ABCD.txt<br/><br/>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.<br/><br/>Thanks for your help<br/>Your posts are contradictory. One shows the dates in the file names as mmddyyyy and the other shows the file names as yyyymmdd.<br/><br/>This snippet is for the mmddyyyy format:<br/> Code: <a>[Select]</a>echo off<br/>setlocal enabledelayedexpansion<br/>for /f "tokens=2" %%v in ("%date%") do (<br/> set today=%%v<br/> set today=!today:/=!<br/>) <br/><br/>echo %today%<br/><br/>This snippet is for the yyyymmdd format:<br/> Code: <a>[Select]</a>echo off<br/>for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (<br/> set today=%%l%%j%%k<br/>)<br/><br/>echo %today% <br/><br/>Choose which snippet meets your needs. The <strong>today</strong> 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 "<em>seeing</em>" the cmd shell environment variables.<br/><br/>Good luck. Thank you.<br/><br/>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.<br/><br/>Xfer.bat<br/>ftp -n -s:E:\ctftp\dataxfer.txt xxx.xxx.xxx.xxx<br/>PAUSE<br/><br/><br/><br/>dataxfer.txt<br/><br/>user <a href="https://interviewquestions.tuteehub.com/tag/username-238054" style="font-weight:bold;" target="_blank" title="Click to know more about USERNAME">USERNAME</a> password<br/>put E:\ctftp\20100618ABCD.txt<br/>rename 20100618ABCD.txt ack<br/>bye<br/><br/>I need to see the text of the transfer and found this does it for me. <br/><br/>Thanks again!<br/> Quote</p><blockquote>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.<br/></blockquote> <br/>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.<br/><br/>Thanks<br/> Quote from: Spoiler on June 21, 2010, 12:06:25 PM<blockquote>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.<br/><br/>Thanks<br/><br/></blockquote> <br/>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.<br/><br/> Code: <a>[Select]</a>echo off<br/>for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (<br/> set today=%%l%%j%%k<br/>)<br/><br/>> E:\ctftp\dataxfer.txt echo username password <br/>>> E:\ctftp\dataxfer.txt echo put E:\ctftp\%today%ABCD.txt <br/>>> E:\ctftp\dataxfer.txt echo ren E:\ctftp\%today%ABCD.txt ack <br/>>> E:\ctftp\dataxfer.txt echo bye <br/><br/>ftp -n -s:E:\ctftp\dataxfer.txt xxx.xxx.xxx.xxx<br/>del E:\ctftp\dataxfer.txt<br/>pause<br/><br/>I couldn't determine if the ABCD part of the file name was static or <a href="https://interviewquestions.tuteehub.com/tag/changed-913862" style="font-weight:bold;" target="_blank" title="Click to know more about CHANGED">CHANGED</a> from day to day. The snippet may need further tweaks.<br/><br/>Good luck. Howdy,<br/><br/>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. <br/><br/>Thanks again.<br/><br/> Quote<blockquote>> E:\ctftp\dataxfer.txt echo username password </blockquote> <br/>I had to make a small change so it read echo user username password<br/><br/>Things work great now. Thanks again for your help!<br/><br/></body></html> | |