Page 1 of 1
Refer to file made by date / time variable
Posted: 17 Oct 2021 09:10
by drgt
Suppose
Dir /a-D /b >%date%%time%.txt
How to refer to that file further down the code?
Time would have advanced so %date%%time%.txt won't be found.
Re: Refer to file made by date / time variable
Posted: 17 Oct 2021 09:41
by aGerman
You know, there is a "Search this forum..." field directly on top of the list view of threads ...
Obviously you're asking questions before you even tried out anything. Not only that %time% advances, it also contains colons which are not allowed in file names. Use WMIC. The FOR /F loop in
this thread creates a %LocalDateTime% variable that you can cut off after 14 characters in order to contain yyyyMMddHHmmSS. This order has also the adwantage of getting properly sorted in an explorer list view. And obviously a defined variable containing the date-time string can be re-used subsequently in the code, because its value doesn't change anymore.
Steffen
Refer to file made by date / time variable
Posted: 17 Oct 2021 10:02
by drgt
Thank you Steffen.
I would have never found it...
Regarding the colons you mentioned, that is why I wrote "suppose'.
Re: Refer to file made by date / time variable
Posted: 17 Oct 2021 11:28
by aGerman
drgt wrote: ↑17 Oct 2021 10:02
I would have never found it...
Do you actually believe that I recall thousands of threads and posts? Guess how I find the topics I link in your threads
Steffen
Refer to file made by date / time variable
Posted: 17 Oct 2021 12:21
by drgt
Re: Refer to file made by date / time variable
Posted: 17 Oct 2021 12:43
by aGerman
E.g. if you want to get a timestamp as name for your file:
- timestamp.png (74.62 KiB) Viewed 7205 times
(yellow emphasizing is mine)
And once you know that WMIC is worth doing further investigation, just do it.
Steffen
Re: Refer to file made by date / time variable
Posted: 17 Oct 2021 13:03
by drgt
Thanks again. I will try again when I get to pc