Batch Script : Find Files with Timestamp in Folder
Closed
soumyajit9
Posts
4
Registration date
Tuesday April 17, 2018
Status
Member
Last seen
April 18, 2018
-
Updated on Apr 17, 2018 at 04:58 PM
soumyajit9 Posts 4 Registration date Tuesday April 17, 2018 Status Member Last seen April 18, 2018 - Apr 18, 2018 at 06:45 PM
soumyajit9 Posts 4 Registration date Tuesday April 17, 2018 Status Member Last seen April 18, 2018 - Apr 18, 2018 at 06:45 PM
Related:
- Batch get timestamp
- Batch file output to text file with timestamp ✓ - Programming Forum
- Batch copy folder ✓ - Programming Forum
- Whatsapp timestamp - Guide
- Batch file open folder ✓ - Windows Forum
- Ping batch file output to text - Guide
Apr 17, 2018 at 06:19 PM
However, I want to be able to only pull out one file with the current date stamp as of the machine and output it to a log file. The script should be able to find the system date and use the params to find a file with the datestamp.
I am currently using below script:
@echo off
dir %1 /b /o:gn > "%temp%\Listing"
start /w notepad "%temp%\Listing"
del "%temp%\Listing"
exit
How do I only extract the file which has the current date stamp as on the machine ? This is where I am stuck at. How do I define variables for this ?
Apr 18, 2018 at 04:19 PM
If Log.log already exist, it will over write it. If you wish to append to the log.log use the ">" instead of the ">>".
Apr 18, 2018 at 04:52 PM
For example, from that folder, I wish to only extract and write to log, the file which has date stamp - TESTFILE20180418.dat ?
Apr 18, 2018 at 06:13 PM
Cut and paste the code below, then see what it produces. Modify your code based on the result.
for /f %%i in ('dir /b/a-d/od/t:c %yourfoldervariable%\WhatEverFileNameYouWish.*') do set LAST=%%i
echo The Most recently created file is %LAST%>>%LOGFILE%
SET THEWHOLARCHIVE=%thearchivefolder%\%LAST%
echo THE NEWEST ARCHIVE FOLDER IS SET TO %THEWHOLARCHIVE%>>%LOGFILE%
Give that a try!
Have fun!