Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Batch Script MoveTo CopyTo Delete Files of a specified size (http://www.go4expert.com/forums/batch-script-moveto-copyto-delete-files-t23223/)

Cleptography 6Sep2010 23:26

Batch Script MoveTo CopyTo Delete Files of a specified size
 
This script will move, copy, or delete files of a specified size in the current directory

Code:

@echo off

:--------------------------------------:
:                                      :
:      MoveTo CopyTo Delete Files      :
:        Of a Specified Size          :
:                                      :
:--------------------------------------:

::
REM This script takes command line arguments and moves, copies, or deletes
REM Files based on size in the current directory
REM The compare-op arguments are the same as the standard if in cmd
REM EQU NEQ LSS LEQ GTR GEQ
::

:: Check args if not exist goto Usage
if [%1]==[] goto Usage

:BEGIN-FUNCTION
    for %%x in (*) do (
        if /i "%%x"=="IfFile.bat" (echo.
        ) else if %%~zx %~1 %~2  (
            if /i "%~3"=="MoveTo" (move "%%x" "%~4"
    ) else  if /i "%~3"=="CopyTo" (copy "%%x" "%~4"
    ) else  if /i "%~3"=="Delete" (del /f /q  "%%x"
) ) )
goto :EOF
:END-FUNCTION

:Usage
echo.Usage:    %0 [(compare-op) (size) (switch) (location)]
echo.
echo.Switches:
echo.          MoveTo
echo.          CopyTo
echo.          Delete
echo.
echo.Examples: %0 EQU 50 MoveTo "C:\Program Files"
echo.          %0 NEQ 50 CopyTo "C:\Program Files"
echo.          %0 LSS 50 Delete
echo.



All times are GMT +5.5. The time now is 14:40.