Skip to content

Instantly share code, notes, and snippets.

@hrsetyono
Last active May 14, 2021 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrsetyono/8202f168b26d17ab8e5e3c99d1870fe3 to your computer and use it in GitHub Desktop.
Save hrsetyono/8202f168b26d17ab8e5e3c99d1870fe3 to your computer and use it in GitHub Desktop.
Folder Management in Windows with CLI

Remove all empty directories

for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d"

7Zip - Compress each directories into its own zip

Require 7zip installation to be added to PATH

Put the parent directory inside the zip:

for /D %d in (*.*) do 7z a -tzip "%d.zip" "%d"

Don't put the parent directory inside the zip:

for /D %d in (*.*) do 7z a -tzip "%d.zip" ".\%d\*"

Rename All Files in All Folders into [FolderName]_[Number]

Create a .bat file containing this: (The .bat file name shouldn't be a reserved keyword like 'rename')

@echo off
pushd "Folder"
for /d %%D in (*) do (
  for %%F in ("%%~D\*") do (
    for %%P in ("%%F\..") do (
      ren "%%F" "%%~nxP_%%~nxF"
    )
  )
)
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment