echo My_File_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt<\/strong><\/p>\n<\/blockquote>\n<\/blockquote>\nthe same in the script<\/p>\n
All the best,<\/p>\n
Alex.<\/p>","upvoteCount":2,"datePublished":"2017-04-04T19:12:30.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/4","author":{"@type":"Person","name":"alexgaft","url":"https://community.spiceworks.com/u/alexgaft"}},{"@type":"Answer","text":"
If you don’t want to go another route, here’s what you can change in your batchfile:<\/p>\n
Replace CIF04042017 with CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%<\/p>\n
Here’s what it’d look like:<\/p>\n
del “D:\\Data\\Paymentus\\Input\\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.csv” \ndel “D:\\Data\\Paymentus\\Input\\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.ctl”<\/p>","upvoteCount":1,"datePublished":"2017-04-04T19:20:00.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/5","author":{"@type":"Person","name":"kaosaephan","url":"https://community.spiceworks.com/u/kaosaephan"}},{"@type":"Answer","text":"
Man, cmd date processing is terse. \nBe careful to verify that the commands produce the expected output as the locale of your systems will matter. A lot.<\/p>\n
Alex’s powershell command is almost correct:<\/p>\n
$date = get-date -Format MMddyyyy\n<\/code><\/pre>\njust need the format to be the correct one <\/p>","upvoteCount":2,"datePublished":"2017-04-04T19:21:43.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/6","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"\n\n
<\/div>\n
M Boyle:<\/div>\n
\nAlex’s powershell command is almost correct:<\/p>\n<\/blockquote>\n<\/aside>\n
Alex’s is 100% correct, if you are in Germany… day, month, year lolOld habits… <\/p>","upvoteCount":3,"datePublished":"2017-04-04T19:23:14.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Thank you all for your help! I just got back to the office and will try out your suggestions.<\/p>","upvoteCount":0,"datePublished":"2017-04-05T12:06:13.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/8","author":{"@type":"Person","name":"dustinsmith7263","url":"https://community.spiceworks.com/u/dustinsmith7263"}},{"@type":"Answer","text":"
\nEDIT DISREGARD QUESTION 2, I figured it out. you use the ` to signify a line break.<\/strong><\/p>\n<\/blockquote>\nNo. `n is a line break.<\/p>\n
`n # that's a line break. Inside \"a double `n quoted string\".\n<\/code><\/pre>\n(for clarity).<\/p>","upvoteCount":2,"datePublished":"2017-04-05T12:56:20.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/9","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
Thank you!<\/p>","upvoteCount":0,"datePublished":"2017-04-05T13:01:26.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/10","author":{"@type":"Person","name":"dustinsmith7263","url":"https://community.spiceworks.com/u/dustinsmith7263"}},{"@type":"Answer","text":"
\n1.) 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.<\/p>\n<\/blockquote>\n
The last line of his script:<\/p>\n
$data | out-file \"C:\\file.bat\" -Force\n<\/code><\/pre>\nYou change the path to the correct one and it will overwrite that file. The -force is needed as the target will already exist.<\/p>","upvoteCount":2,"datePublished":"2017-04-05T13:02:11.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/11","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
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.<\/p>\n
<disclaimer: the poster does not provide actual bacon><\/p>","upvoteCount":1,"datePublished":"2017-04-05T13:29:42.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/12","author":{"@type":"Person","name":"philgman","url":"https://community.spiceworks.com/u/philgman"}},{"@type":"Answer","text":"\n\n
<\/div>\n
philgman:<\/div>\n
\nGreat example of having a dozen ways to accomplish the same(ish) result. This is why i live this place. Everybody gets BACON this morning.<\/p>\n
<disclaimer: the poster does not provide actual bacon><\/p>\n<\/blockquote>\n<\/aside>\n
I had a bacon sammich earlier. It was most tasty and the kitchen still smells awesome <\/p>","upvoteCount":1,"datePublished":"2017-04-05T13:48:55.000Z","url":"https://community.spiceworks.com/t/help-with-a-script/571791/13","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}}]}}
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
Neally
(Neally)
April 4, 2017, 7:12pm
3
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
alexgaft
(Alex.Gaft)
April 4, 2017, 7:12pm
4
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
psophos
(M Boyle)
April 4, 2017, 7:21pm
6
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
2 Spice ups
Neally
(Neally)
April 4, 2017, 7:23pm
7
Alex’s is 100% correct, if you are in Germany… day, month, year lolOld habits…
3 Spice ups
Thank you all for your help! I just got back to the office and will try out your suggestions.
psophos
(M Boyle)
April 5, 2017, 12:56pm
9
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
psophos
(M Boyle)
April 5, 2017, 1:02pm
11
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
philgman
(philgman)
April 5, 2017, 1:29pm
12
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
psophos
(M Boyle)
April 5, 2017, 1:48pm
13
I had a bacon sammich earlier. It was most tasty and the kitchen still smells awesome
1 Spice up