Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Find the latest file in a series of folders

Status
Not open for further replies.

jeffwest21

IS-IT--Management
Apr 4, 2013
60
GB
I have the followin g code in a batch file
Code:
@ECHO OFF 
SETLOCAL ENABLEDELAYEDEXPANSION 

SET "FFPath= \\server\ROI\"
SET "NewPath= \\server\ROI\"
REM Arbitrary yyymmdd starting point, nothing will be older than it
SET NewestDate=20130101

ECHO Recursively searching %FFPath% 
echo.

FOR /F "delims=" %%I in ('DIR %FFPath%\C*.rtf /a:-d /s /b') DO (
   SET FullDate=%%~tI
   
   REM Set CurrDate to yyyymmdd format.  Note:  Will fail if regional settings changed.
   SET CurrDate=!FullDate:~6,4!!FullDate:~0,2!!FullDate:~3,2!

   If !CurrDate! gtr !NewestDate! (
      SET NewestDate=!CurrDate!
      SET NewestFile=%%~fI
   )
)

ECHO Copying %NewestFile% to %NewPath%
ECHO.
COPY /Y "%NewestFile%" "%NewPath%"
ECHO. 
PAUSE

What happens is this, another batch file sends data in dataed folders to the directory i am looking at, I want to find the latest folder, and get the files out of it and move them elsewhere for a scheduled task to pick up and process. The issue is they are run overnight so no human interaction needs to happen.

I am getting an error that says the folder/file do not exist yet a folder dated today exists and in it are files aslo dated today, this is really bugging me as it will finish off a process I am trying to complete.

'Clever boy...'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top