0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【忘備録】ディレクトリ内のフォルダを個別ZIP化コマンド

Last updated at Posted at 2025-01-30

Windows

フォルダをドラッグアンドドロップして使用します。
sendtoに作成すると便利

前提条件

  • 7ZIPインストール済み
@echo off 
set ZIP_PATH="C:\Program Files\7-Zip\7z.exe" 
for %%f in (%*) do ( 
%ZIP_PATH% a -tzip %%f.zip %%f 
) 

exit /B 0 

Linux

/usr/local/bin/に格納しておくと便利(chomod +xを忘れずに。)
ZIPNowfolder(ファイル名は任意)で保存し、個別にZIP化したいフォルダがあるディレクトリで実行すればOK

前提条件

  • zipコマンド使用可
#!/bin/bash

# 現在のディレクトリをターゲットディレクトリとして設定
TARGET_DIR=$(pwd)

# ターゲットディレクトリ内の各サブディレクトリを処理
for dir in "$TARGET_DIR"/*/; do
  # サブディレクトリ名を取得
  dirname=$(basename "$dir")
  
  # ZIPファイルの名前を設定
  zipfile="$TARGET_DIR/$dirname.zip"
  
  # サブディレクトリをZIPに圧縮
  zip -r "$zipfile" "$dir"
done
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?