WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on February 09, 2016, 12:09:41 PM

Title: Daily file naming sequence reset
Post by: MW4 on February 09, 2016, 12:09:41 PM
Hello everyone,
I use the "How to Watch for Files and Then Do Something" on a server to process files as they come in.
Normally there is only one file per day which makes processing easy because there is a set file name and no other files arrive as processing occurs.

I have a new requirement for multiple files in a day and the possibility that files will come in as a process is working.
I need to name in a sequential fashion as files come in every day like T1.txt, T2.txt, T3.txt so I can process sequentially and look for the next sequenced file.

I can set the Variable to increment as files come in, but what would be the best way to reset to 1 at midnight?

Hopefully this is not too convoluted of an explanation.
Title: Re: Daily file naming sequence reset
Post by: JTaylor on February 09, 2016, 12:45:02 PM
What if you just used

   file_name = "t":StrReplace(TimeYmdHms(),":",""):".txt"

to create the name.  They will sort properly and you don't have to worry about resetting.

Jim
Title: Re: Daily file naming sequence reset
Post by: MW4 on February 09, 2016, 01:30:03 PM
The processing reaches out in sequence to process in the order that they came in.

Presently I'm using a variation of what you suggested, but I'd like to get it in the format of T1, etc

I have a few uses for a daily resettable variable, so I'd like to find a solution for that.
Title: Re: Daily file naming sequence reset
Post by: JTaylor on February 09, 2016, 01:51:34 PM
With each loop save the time (not date part) and whenever the new time is less than the saved time reset your counter.

Jim
Title: Re: Daily file naming sequence reset
Post by: MW4 on February 09, 2016, 02:06:55 PM
I like that....let me give it a try
Title: Re: Daily file naming sequence reset
Post by: ....IFICantBYTE on February 09, 2016, 02:34:58 PM
Watch out for Daylight Saving if it affects your area... the time will go back an hour and if a file came in then and it was less than an hour since the last one, then the new time will be older than the saved time!
If you use Universal time then it shouldn't be an issue.
Title: Re: Daily file naming sequence reset
Post by: MW4 on February 09, 2016, 03:22:30 PM
these files wouldn't come in at those hours, it's only 9-5 business hours, but good point!