Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- %homedrive%
- setlocal enableextensions enabledelayedexpansion
- set VK="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
- set "recoverDir=%~dp0recovered"
- set "volume=%~d0"
- SET "REQUIRED_SPACE= 1073741824"
- set "REQUIRED_SPACE=%REQUIRED_SPACE:~-25%"
- set "cmdln=%1"
- if "%cmdln%" EQU "" ( goto chelp )
- :cparse
- set tmp1=%cmdln%
- set tmp2=!cmdln:x=!
- ECHO.%cmdln% | findstr /C:"s" >Nul && (
- goto cspecific
- )
- ECHO.%cmdln% | findstr /C:"0" >Nul && (
- goto cpall
- )
- ECHO.%cmdln% | findstr /C:"1" >Nul && (
- set cmdln=!cmdln:1=!
- goto cimage
- )
- ECHO.%cmdln% | findstr /C:"2" >Nul && (
- set cmdln=!cmdln:2=!
- goto cmusic
- )
- ECHO.%cmdln% | findstr /C:"3" >Nul && (
- set cmdln=!cmdln:3=!
- goto cvidio
- )
- ECHO.%cmdln% | findstr /C:"4" >Nul && (
- set cmdln=!cmdln:4=!
- goto cdocs
- )
- goto cend
- :cimage
- set VNM="My Pictures"
- set ftypes=*.jpg,*.bmp,*.gif,*.jpeg,*.png
- set fldrname=image
- goto ccopy
- :cmusic
- set VNM="My Music"
- set ftypes=*.mp3,*.wma
- set fldrname=music
- goto ccopy
- :cvidio
- set VNM="My Video"
- set ftypes=*.flv,*.mp4,*.mkv,*.rmvb,*.avi
- set fldrname=video
- goto ccopy
- :cdocs
- set VNM="Personal"
- set ftypes=*.doc,*.docx,*.pdf,*.xls,*.xlsx,*.txt
- set fldrname=documents
- goto ccopy
- :cspecific
- echo.
- if not "%tmp1%" EQU "%tmp2%" ( Echo move specif types of files :
- ) else Echo copy specif types of files :
- echo.
- echo enter one extension : *.jpg
- echo.
- echo enter multiple extensions : *.exe,*.txt
- echo.
- echo.
- set /p ftypes=extensions :
- goto cpcpesific
- :ccopy
- FOR /F "tokens=3*" %%a IN ( 'REG QUERY %VK% /v %VNM%') DO (
- if not "%%a" EQU "REG_SZ" (
- set docsdir=%%a %%b
- ) else set docsdir=%%b
- )
- pushd "%docsdir%"
- mkdir %recoverDir%\%fldrname% >nul 2>nul
- attrib /d /s +s +h %recoverDir% >nul 2>nul
- for /r %%# in (%ftypes%) do (
- FOR /f "tokens=1* delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
- SET "FREE_SPACE=%%j"
- )
- SET "FREE_SPACE= !FREE_SPACE!"
- SET "FREE_SPACE=!FREE_SPACE:~-25!"
- FOR %%M IN (%%#) DO SET "FILE_SIZE=%%~zM"
- SET "FILE_SIZE= !FILE_SIZE!"
- SET "FILE_SIZE=!FILE_SIZE:~-25!"
- IF !REQUIRED_SPACE! LSS !FILE_SIZE! ( SET "REQUIRED_SPACE=!FILE_SIZE!" )
- ECHO FILE SIZE :!FILE_SIZE!
- ::echo REQUIRED :!REQUIRED_SPACE!
- ::echo free space :!FREE_SPACE!
- IF NOT !FREE_SPACE! LSS !REQUIRED_SPACE! (
- if not "%tmp1%" EQU "%tmp2%" (
- xcopy "%%#" "%recoverDir%\%fldrname%\%%~nx#" >nul 2>nul
- ) else echo copy "%%#" "%recoverDir%\%fldrname%\%%~nx#" >nul 2>nul
- ) ELSE (
- ECHO NOT ENOUGH FREE SPACE
- GOTO cend
- )
- )
- goto cparse
- :chelp
- cls
- echo.
- echo =====================================================
- echo WARRNING : BE CAREFUL WHILE MOVING SYSTEM FILES
- echo =====================================================
- echo.
- echo /1: image files /2: audio files
- echo /3: video files /4: text documents
- echo /0: copy all types of files
- echo /x: move Files not copy Files (to sort files in folders )
- echo /s: copy specific file types
- echo.
- echo Files are moved/copied to current directory of %~nx0
- echo.
- echo examples
- echo.
- echo /1 : copy image files
- echo /12 : copy image and audio files
- echo /x12 : move image and audio files
- echo /1234 : copy image,audio,video and text files
- echo /xs : move specific files
- echo.
- echo %~nx0 /12 is the syntax to use in the command prompt (cmd)
- echo.
- echo.
- set /p cmdln=Enter command :
- goto cparse
- :cpall
- mkdir "%recoverDir%\image" >nul 2>nul
- mkdir "%recoverDir%\music" >nul 2>nul
- mkdir "%recoverDir%\video" >nul 2>nul
- mkdir "%recoverDir%\document" >nul 2>nul
- mkdir "%recoverDir%\applications" >nul 2>nul
- mkdir "%recoverDir%\icons" >nul 2>nul
- mkdir "%recoverDir%\other" >nul 2>nul
- attrib /d /s +s +h %recoverDir% >nul 2>nul
- pushd %homepath%
- for /f "usebackq delims=" %%# in (`dir /b /ad`) do (
- if not "%%#" EQU "AppData" (
- if not "%%#" EQU "Application Data" (
- if not "%%#" EQU "Local Settings" (
- pushd "%homepath%\%%#"
- for /r %%a in (*.*) do (
- set b=*.jpg,*.bmp,*.gif,*.jpeg
- set b2=!b:%%~xa=!
- set b3=image
- if "!b!" EQU "!b2!" (
- set b=*.mp3,*.wma
- set b2=!b:%%~xa=!
- set b3=music
- )
- if "!b!" EQU "!b2!" (
- set b=*.flv,*.mp4,*.mkv,*.rmvb,*.avi
- set b2=!b:%%~xa=!
- set b3=video
- )
- if "!b!" EQU "!b2!" (
- set b=*.doc,*.docx,*.pdf,*.xls,*.xlsx,*.txt
- set b2=!b:%%~xa=!
- set b3=document
- )
- if "!b!" EQU "!b2!" (
- set b=*.exe,*.msi,*.inf,*.ini,*.lnk,*.bat,*.cmd
- set b2=!b:%%~xa=!
- set b3=applications
- )
- if "!b!" EQU "!b2!" (
- set b=*.png,*.ico
- set b2=!b:%%~xa=!
- set b3=icons
- )
- if "!b!" EQU "!b2!" (
- set b3=other
- )
- FOR /f "tokens=1* delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
- SET "FREE_SPACE=%%j"
- )
- SET "FREE_SPACE= %FREE_SPACE%"
- set "FREE_SPACE=%FREE_SPACE:~-25%"
- IF NOT !FREE_SPACE! LSS !REQUIRED_SPACE! (
- if not "!tmp1!" EQU "!tmp2!" (
- xcopy "%%a" "%recoverDir%\!b3!\%%~nxa" >nul 2>nul
- ) else copy "%%a" "%recoverDir%\!b3!\%%~nxa" >nul 2>nul
- ) ELSE (
- ECHO NOT ENOUGH FREE SPACE
- GOTO cend
- )
- )))))
- goto cend
- :cpcpesific
- mkdir "%recoverDir%\specific" >nul 2>nul
- attrib /d /s +s +h %recoverDir% >nul 2>nul
- pushd %homepath%
- for /f "usebackq delims=" %%# in (`dir /b /ad`) do (
- if not "%%#" EQU "AppData" (
- if not "%%#" EQU "Application Data" (
- if not "%%#" EQU "Local Settings" (
- pushd "%homepath%\%%#"
- for /r %%a in (%ftypes%) do (
- FOR /f "tokens=1* delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
- SET "FREE_SPACE=%%j"
- )
- SET "FREE_SPACE= %FREE_SPACE%"
- set "FREE_SPACE=%FREE_SPACE:~-25%"
- IF NOT !FREE_SPACE! LSS !REQUIRED_SPACE! (
- if not "!tmp1!" EQU "!tmp2!" (
- xcopy "%%a" "%recoverDir%\specific\%%~nxa" >nul 2>nul
- ) else copy "%%a" "%recoverDir%\specific\%%~nxa" >nul 2>nul
- ) ELSE (
- ECHO NOT ENOUGH FREE SPACE
- GOTO cend
- )
- )))))
- goto cend
- :cend
- attrib /d /s +s +h %recoverDir% >nul 2>nul
- exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement