| 1. |
Solve : Edit a text file? |
|
Answer» Hi All,
But does ftp, when it reads data.txt for its commands convert %current_date% to the env var , or does it read that text literally? This happened to me recentl I ended up using my batch to write the contents of the ftp script each time it was called, in which case, the batch expansion of the date variable will occur and the literal value will be written to the script file Cheers GrahamQuote This happened to me recentl You mean that the original poster would need to use dworley's line of code to set the env var, then run a batch file something like this? : Code: [Select] @echo off echo user Username Password > data.txt echo put somefile%current_date%.txt >> data.txt echo bye >> data.txt I am not sure thats going to work. My goal was to inject a new name for a file that had the current date into a text file. That way the FTP session would use the new data.txt file for its session. Maybe I don't understand what was suggested. Hi, I re-read the answer and I think I understand it now....ok I am a little slow. I am going to give it a try. Thanks for your help!! Quote Hi, And I thought I was the only one that had to go over things more than once. Quote I am going to give it a try. That's the spirit! Quote Thanks for your help!! We'll see. If it works. I hope it does help you. Let us know what happens. Quote
Don't hesistate to quote anything you are unsure of, and ask. Ok...I must be doing something wrong. I copied the sample code above and added the set date from above and it worked fine. It wrote me a data.txt file and it had everything in it that I would need to use for a FTP session. Than I made the changes to ADD the real stuff I wanted in the data.txt file and its not working any more. Here is my bat file: set current_date=%date:~10,4%%date:~4,2%%date:~7,2% @echo off echo user sm2thy joneser > data.txt echo cd /cool/directory/OK.Now >> data.txt echo put C:\FTP\TEMP\BOB.LCT%current_date%.DAT >> data.txt echo put C:\FTP\TEMP\BOB.TCL%current_date%.DAT >> data.txt echo put C:\FTP\TEMP\FEDWL.TXT >> data.txt echo bye >> data.txt pause And here is the out put in the data.txt file. user sm2thy joneser cd /cool/directory/OK.Now put C:\FTP\TEMP\BOB.LCT20070118 .DAT put C:\FTP\TEMP\BOB.TCL20070118 .DAT put C:\FTP\TEMP\FEDWL.TXT bye pause I don't know how to get rid of the extra space after the date in the files name. Also can someone tell me about the > in the bat file? Why is there only one of them in the first line but all the others need 2? Thanks for your help!! Quote Ok...I must be doing something wrong. I copied the sample code above and added the set date from above and it worked fine. It wrote me a data.txt file and it had everything in it that I would need to use for a FTP session. Great! That sounds good, so far. Quote Than I made the changes to add the real stuff I wanted in the data.txt file and its not working any more. I don't have XP, so I can't try that command and experiment with the switches, etc. Hopefully somebody else will be along soon that can work it out for you. Quote Also can someone tell me about the > in the bat file? Why is there only one of them in the first line but all the others need 2? Those are redirection symbols. Means 'take the output and instead of printing it to the screen, print it to the file which is named next'. One ' > ' also means, ' and if that filename ALREADY exists, overwrite it'. Two '>>' means, ' and if that filename already exists, don't overwrite it, but append to it' . Check the file date/time stamp, after you've run your batch file more than once. data.txt is always new, isn't it? That line using only one > is creating a new data.txt each time. Quote Thanks for your help!! You are welcome. I hope you get that blank figured out soon. You're almost there. A space is a very real character and is included in the set statement WHENEVER the space bar is used. Ensure there is no trailing space after the LAST % symbol in your set statement: set current_date=%date:~10,4%%date:~4,2%%date:~7,2%[highlight] [/highlight] Good luck. 8-)Very cool! I checked and I did have a space at the end. I would have never thought of that. Thanks!! Now I am going to plug all of this into the full script. Thanks for everyones help! |
|