Batch to search all drives and copy newest

Dell / OPTIPLEX GX620
November 18, 2009 at 06:37:18
Specs: Windows XP, 2.79GHZ/1GB
I found a batch script to search all drives and delete the autorun.inf file on this forum I want that method but change it up a bit. I would like to Search all drives for a specific file and copy the newest one that it finds and rename it with a timestamp. Here is what I have so far:

ECHO Searching for databases...
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set ss=%%o
)
)
SET STAMP=%dow%_%yy%%mm%%dd%_%hh%.%min%.%ss%
for /f "tokens=1,2 delims=\ " %%a in ('fsutil fsinfo drives^|more/e/t0') do (if "%%b"=="" (set drive=%%a) else set drive=%%b
echo Scanning !drive!
for /f "skip=1 tokens=* delims= " %%f in ('dir !drive!\*core32.mdb /b /a-d /o-d /s 2^>nul') do @if exist "%%f" XCOPY /K "%%f" !managepath!\Tools\Import\ & echo %%f)
ECHO Scanning COMPLETE!!!
PAUSE
CLS
RENAME !managepath!\Tools\Import\*core32.mdb b4conv_%STAMP%.mdb


See More: Batch to search all drives and copy newest

Report •


#1
November 18, 2009 at 07:09:16
Run this and post a few lines of the output.

=========================
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d \files') do (
echo %%a %%~Ta
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
November 18, 2009 at 07:46:21
I get
File Not Found

Report •

#3
November 18, 2009 at 07:50:06
Ok changed to
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d \*core32.mdb') do (
echo %%a %%~Ta
)
Pause

Now I get:
C:\smcore32.mdb 11/17/2009 11:31 AM
C:\Documents and Settings\jestes\Desktop\smcore32.mdb 11/16/2009 01:30 PM
Press any key to continue . . .


Report •

Related Solutions

#4
November 18, 2009 at 08:05:31
Ignoring for the moment the mess which will be created by AM/PM and that 01:30 PM [sic] is meaningless, what you need to do is re-order the date so that you have YYYYMMDD making sorting possible.


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question