Okay Yall, I have ZERO experience with programming/batch files and need some help.
Everyday, I have to update a batch file with today’s date so that our payments vendor will accept our daily files that we upload. Yes I know this sucks and is stupid but we are stuck with it. Its really not a problem except for days where I am not at work or forget to do it lol. I want to create a script or something that will do this for me. Any ideas? Here is a sample of what the batch file looks like, everywhere you see a date(mmddyyyy) i have to change it to todays date. Thanks yall!

9 Spice ups

Try this

for /f “tokens=1-5 delims=/ " %%d in (”%date%") do rename “C:\file.csv” TEST%%e%%f%%g.csv

Under the quoted “C:\file.csv” place your original file name. then where it says TEST — place the beginning of the name.

The % areas will give you the current date, and then add your filetype after the g.

For ease of use, if you are currently outputting the file with the same filename, the rest should be extremely easy to automate, you could do this everyday by scheduling it to run at a certain time, and even FTP if they allow for that.

2 Spice ups

I’d create a powershelscript with a here string that would fill that in lol

$date = get-date -Format ddMMyyyy

$data = @"
pscp -pw banana input\CIF$date.csv
pscp -pw banana input\CIF$date.ctl
del "D:\stuff\too\lazy\to\type\more\CIF$date.csv"
del "D:\stuff\too\lazy\to\type\more\CIF$date.ctl"
"@

$data | out-file "C:\file.bat" -Force

Run it as scheudled task to create that thing everyday or whenever needed.

8 Spice ups

Hi, try this in cmd:

echo My_File_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt

the same in the script

All the best,

Alex.

2 Spice ups

If you don’t want to go another route, here’s what you can change in your batchfile:

Replace CIF04042017 with CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%

Here’s what it’d look like:

del “D:\Data\Paymentus\Input\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.csv”
del “D:\Data\Paymentus\Input\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.ctl”

1 Spice up

Man, cmd date processing is terse.
Be careful to verify that the commands produce the expected output as the locale of your systems will matter. A lot.

Alex’s powershell command is almost correct:

$date = get-date -Format MMddyyyy

just need the format to be the correct one :slight_smile:

2 Spice ups

Alex’s is 100% correct, if you are in Germany… day, month, year lolOld habits… :stuck_out_tongue:

3 Spice ups

Thank you all for your help! I just got back to the office and will try out your suggestions.

EDIT DISREGARD QUESTION 2, I figured it out. you use the ` to signify a line break.

No. `n is a line break.

`n  # that's a line break. Inside "a double `n quoted string".

(for clarity).

2 Spice ups

Thank you!

1.) How can I tell the script to overwrite the previous “file.bat” since I will be running this daily with the same file name, it will need to overwrite the previous days file.

The last line of his script:

$data | out-file "C:\file.bat" -Force

You change the path to the correct one and it will overwrite that file. The -force is needed as the target will already exist.

2 Spice ups

Great example of having a dozen ways to accomplish the same(ish) result. This is why i love this place. Everybody gets BACON this morning.

<disclaimer: the poster does not provide actual bacon>

1 Spice up

I had a bacon sammich earlier. It was most tasty and the kitchen still smells awesome :slight_smile:

1 Spice up