Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
Last active March 22, 2025 19:21
Show Gist options
  • Save StudioEtrange/175755cb5d469f380fc5a041692e7b21 to your computer and use it in GitHub Desktop.
Save StudioEtrange/175755cb5d469f380fc5a041692e7b21 to your computer and use it in GitHub Desktop.
Various files and folders manipulation

Various files and folders manipulation tips

Various files and folders manipulation

Flat folder content

move all files, folder and subfiles of a root folder inside this root folder in a flatten way

Move files outside its folder

  • windows :

    cd /D X:\FOLDER
    for /D %A in ("*") do @for %B in ("%~fA"\*.*) do move /y "%B" "%~dpB..\"
    

Move files inside its own folder

  • linux :

    cd /FOLDER
    for f in *; do mkdir "${f%.*}"; mv "$f" "${f%.*}"; done
    

Delete empty folders

  • windows :

    set "FOLDER=X:\FOLDER"
    for /r "%FOLDER%" /d %F in (.) do @dir /b "%F" | findstr "^" >nul || echo %~fF && rmdir /Q "%~fF"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment