date variable in script file

Advertisement

murrayb3024
Guest

date variable in script file

We create a daily file that I need to upload to a vendor. I can hard code the file name and that works but it changes daily so I need to send a file like:

c:\myfilepath\myFile_20130122.txt where the date portion changes daily and needs to be yyyymmdd.

I am not having luck with that part. Any help is appreciated.

Reply with quote

Advertisement

mjb0622
Guest

Date parameter within text

Does anyone have a sample of this solution. I am trying to do the same with a date.
The file name cahnages by day and i need to update several systems with the same file.
How do I pass the date to the text file?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,271
Location:
Prague, Czechia

Re: Date parameter within text

mjb0622 wrote:

Does anyone have a sample of this solution. I am trying to do the same with a date.
The file name cahnages by day and i need to update several systems with the same file.
How do I pass the date to the text file?
See example here.
https://winscp.net/eng/docs/script_download_timestamped_filename
Or even better, use WinSCP .NET assembly:
https://winscp.net/eng/docs/library
_________________
Martin Prikryl

Reply with quote

Guest

Variable date appended to filename in a bat file

You can configure date variables in a dos box. Once you prepare the date format you need, then set it to a variable name. Then you can use it as part of the filename to either send or get.
From within te bat file, you can call winscp to open an sftp while passing the date variable to the winscript. Be sure to enclose it with % signs.

Dos date format is mm/dd/yyyy (10 characters). This was run in a dos prompt. The set date is just to test any date you want.
C:\>set date=04/01/2013
C:\>echo %date%
04/01/2013
C:\>set dtmm=%date:~-10,2%
C:\>set dtdd=%date:~-7,2%
C:\>set dtyyyy=%date:~-4,4%
C:\>echo %dtmm%
04
C:\>echo %dtdd%
01
C:\>echo %dtyyyy%
2013
C:\>set dteall=%dtyyyy%%dtmm%%dtdd%
C:\>echo %dteall%
20130401
C:\>
So you can use %dteall% as part of a filename: myfile%dteall% = myfileyyyymmdd
The variable can be used in your winscript if needed.

Reply with quote

Advertisement

You can post new topics in this forum