[windows2000] Re: copy files by date over CLI

  • From: "Sullivan, Glenn" <GSullivan@xxxxxxxxxxxxxx>
  • To: "'windows2000@xxxxxxxxxxxxx'" <windows2000@xxxxxxxxxxxxx>
  • Date: Tue, 6 Jan 2004 13:34:43 -0500

BTW, there were two lines that wrapped in that script... they are the two
lines that do not start with a Space or a Colon.

And the line that starts with "NOW" should have the word "Echo" in front of
it.

HTH,

Glenn Sullivan, MCSE+I  MCDBA
David Clark Company Inc. 

-----Original Message-----
From: Sullivan, Glenn [mailto:GSullivan@xxxxxxxxxxxxxx]
Sent: Tuesday, January 06, 2004 1:31 PM
To: 'windows2000@xxxxxxxxxxxxx'
Subject: [windows2000] Re: copy files by date over CLI


Forfiles from the resource kit...

Stuff it into a FOR command at the CLI, and you should be good to go.

Here is a script (Modified from ASB's DelOld script on the NTSysAdmin list)
that hunts a directory and it's subdirectories for files older than XX days,
and moves them.

<-------Start------->
@ECHO OFF
 rem ==============================================================
 rem === Move Old Files (Win2K/FORFILES Version)
 rem ==============================================================

 rem ==============================================================
 rem === Verify If Syntax Help Is Required/Requested
 rem === Last Modified On 06 Sep 2001
 rem ==============================================================
:NeedHelp
 IF /I "%1"=="" GOTO :HelpMessage
 IF /I "%2"=="" GOTO :HelpMessage
 FOR %%H IN (H HELP) DO IF /I "%1"=="/%%H" GOTO :HelpMessage
 FOR /F %%H IN ('ECHO %* ^| FIND /I "/?"') DO IF NOT ERRORLEVEL 1 GOTO
:HelpMessage


 rem ==============================================================
 rem === Initialize Environment Variables
 rem === Last Modified On 05 Sep 2001
 rem ==============================================================
:Variables
 SETLOCAL
 SET @FOLDER=%~1
 SET @DESTFolder=%~2
 SET @AGE=%3& IF /I "%3"=="" SET @AGE=30
 SET @LOGFILE="%~dp0\Logs\MoveOld.LOG"


 rem ==============================================================
 rem === Recurse Through Subfolders And Move Old Files
 rem === Last Modified On 05 Sep 2001
 rem ==============================================================
:SetFolders
 IF /I NOT EXIST "%~dp0\Logs" MD "%~dp0\Logs"
 ECHO.                                                          >>%@LOGFILE%
 ECHO.                                                          >>%@LOGFILE%
 NOW Hunting Through "%@FOLDER%" And Subfolders For Old Files...
>>%@LOGFILE%
 ECHO.                                                          >>%@LOGFILE%
 ECHO.
 ECHO Hunting Through "%@FOLDER%" And Subfolders For Old Files...
 ECHO.
 FOR /F "TOKENS=*" %%D IN ('FORFILES -p"%@FOLDER%" -d-%@AGE% -s -c"CMD /C
ECHO @PATH\@FILE"') DO CALL :MoveFiles "%%D"


 rem ==============================================================
 rem === Reset Environment Variables and Exit Batch File
 rem === Last Modified On 27 Jun 2000
 rem ==============================================================
:ExitBatch
 ENDLOCAL
 GOTO :EOF


 rem ==============================================================
 rem === SUBROUTINE: Remove Files That Are Over XX Days Old
 rem === Last Modified On 18 Oct 2000
 rem ==============================================================
:MoveFiles
 FOR /F %%G IN ('dir %1 ^| FIND /I ".."') DO IF ERRORLEVEL 0 goto SkipRemove
 rem %* = Current Filename
 ECHO -- Moving %*...
 ECHO -- Moving %*... >>%@LOGFILE%
 ATTRIB -R -S -H %*
 MOVE %* %@DESTFolder%                >>%@LOGFILE%
:SkipRemove
 GOTO :EOF


 rem ==============================================================
 rem === SUBROUTINE: Remove Surrounding Quotes From Variable
 rem === Last Modified On 01 Jul 2001
 rem ==============================================================
:NoQuotes
 rem %1 = Current Filename
 SET %1=%~2
 GOTO :EOF


 rem ==============================================================
 rem === SUBROUTINE: Display Syntax Help For "/?"
 rem === Last Modified On 23 Aug 2001
 rem ==============================================================
:HelpMessage
 ECHO.
 ECHO Syntax Help for MOVEOLD.BAT
 ECHO.
 ECHO === MoveOld {initial_dir} {destination_dir} [age_of_files]
 ECHO.
 ECHO Example: MoveOld C:\STORAGE c:\OldStuff 10
 ECHO          MoveOld D:\HOME c:\OldStuff 90
 ECHO          MoveOld E:\ARCHIVES c:\OldStuff
 ECHO          MoveOld "F:\OLD ARCHIVES" c:\OldStuff
 ECHO          MoveOld "G:\MISCELLANEOUS STUFF" c:\OldStuff 45
 ECHO.
 ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ECHO NOTE: Folder names which contain spaces
 ECHO       should be surrounded by quotes.
 ECHO       Shortnames *can* be surrounded by
 ECHO       quotes if you choose, but it is not
 ECHO       mandatory by any means.
 ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ECHO.
<------------------End Script------------>

HTH,


Glenn Sullivan, MCSE+I  MCDBA
David Clark Company Inc. 

-----Original Message-----
From: Brian Anderson [mailto:BAnderson@xxxxxxxxxx]
Sent: Tuesday, January 06, 2004 1:06 PM
To: windows2000@xxxxxxxxxxxxx
Subject: [windows2000] copy files by date over CLI


I've got a directory of documents on one of our app servers. They're
computer generated documents that have been piling up for a bit. Right now,
in this one directory, there is close to 500k documents. I'm wanting to pull
some of the files out of there. Problem is that the folder seems to be so
big (like 13GB), that explorer just freezes (even if you let it sit for an
hour) trying to open up the folder. Over the command line, I can copy files
fine though. Does anyone know of a way that I could copy files over the
command line using a modified date range as an identifier? The files go back
about 3 years and I would want to move out maybe the first year or so. I
wasn't aware of any specific switches that did that in either copy or xcopy.


Or beyond that, would there be a utility that could do it that anyone is
aware?

thanks,

-brian

Brian Anderson
Serapis Support
Correctional Medical Service
Office (314)919-9868
Mobile (314)239-1398
banderson@xxxxxxxxxx
http://www.serapisonline.com  
********************************************************
This Weeks Sponsor StressedPuppy.com Games
Feeling stressed out? Check out our games to
relieve your stress.
http://www.StressedPuppy.com
********************************************************
To Unsubscribe, set digest or vacation
mode or view archives use the below link.

http://thethin.net/win2000list.cfm
********************************************************
This Weeks Sponsor StressedPuppy.com Games
Feeling stressed out? Check out our games to
relieve your stress.
http://www.StressedPuppy.com
********************************************************
To Unsubscribe, set digest or vacation
mode or view archives use the below link.

http://thethin.net/win2000list.cfm
********************************************************
This Weeks Sponsor StressedPuppy.com Games
Feeling stressed out? Check out our games to
relieve your stress.
http://www.StressedPuppy.com
********************************************************
To Unsubscribe, set digest or vacation
mode or view archives use the below link.

http://thethin.net/win2000list.cfm

Other related posts: