Skip to content

Instantly share code, notes, and snippets.

@ojimac
Created May 13, 2012 09:06
Show Gist options
  • Save ojimac/2687081 to your computer and use it in GitHub Desktop.
Save ojimac/2687081 to your computer and use it in GitHub Desktop.
Macで、カレントディレクトリ内の内容が重複しているファイルを削除するスクリプト
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
files = os.listdir('./')
for file in files:
if re.match('[0-9a-zA-z]+\s2\.[JPG|CR2]', file):
os.remove(file)
@ojimac
Copy link
Author

ojimac commented May 13, 2012

macでは、同じディレクトリ内に同じファイル名のファイルをコピーすると、

ファイル名_2.拡張子
※ _ は半角スペース

のようなファイル名になる。
今回はデジカメで撮った写真(JPG, CR2)が重複してしまった。
一個一個消していくのは面倒なのでスクリプトにしてみた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment