Batch file to compress subdirectories

前端 未结 5 1035
广开言路
广开言路 2021-02-10 09:56

I am trying to write a batch script that will run automatically compressing subdirectories using winrar or 7-zip:

Example:

 My Pictures
    Pics1 (Pics1.         


        
5条回答
  •  清歌不尽
    2021-02-10 10:55

    Another approach if you need to recursively zip files in all subdirs in windows is to use gitbash and the approach described here:

    • If you installed git, right click and chose "Git Bash Here"
    • Type find * -type d ! -empty -execdir sh -c 'cd "$1" && 7z a "$1".7z -x!*/ && cd -' sh {} \;

    This will:

    • retain folderstructure, place each zip in respective subdir
    • recursively zip all files in dirs (excluding empty dirs)
    • name zips with directory name

    You can also exclude specific types with:

    find * -type d -execdir sh -c 'cd "$1" && 7z a "$1".7z -x!*/ -x!*.7z -x!*.zip && cd -' sh {} \;
    

提交回复
热议问题