1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Batch Script MoveTo CopyTo Delete Files of a specified size

Discussion in 'Programming' started by Cleptography, Sep 6, 2010.

  1. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    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.
     

Share This Page