Skip to content

Instantly share code, notes, and snippets.

@arosh
Last active October 7, 2015 21:18
Show Gist options
  • Save arosh/3226833 to your computer and use it in GitHub Desktop.
Save arosh/3226833 to your computer and use it in GitHub Desktop.
rmexe
#!/usr/bin/env python
# coding: utf-8
import sys
from sys import stderr
import os
from os import path
import re
import shutil
def main():
workdir = path.abspath(os.curdir)
files = os.listdir(workdir)
candidates = []
for item in files:
# 実行可能なファイルであるとき
if path.isfile(item) and os.access(item, os.X_OK):
candidates.append(item)
continue
# 末尾が'.dSYM'のフォルダであるとき
if path.isdir(item) and item.endswith('.dSYM'):
candidates.append(item)
continue
stderr.write('candidates for delete are below\n')
stderr.write('--\n')
for item in candidates:
sys.stderr.write('%s\n' % item)
stderr.write('--\n')
stderr.write('delete all? (y/n [n]) ')
try:
response = raw_input()
except EOFError:
pass
else:
if response == 'y':
for item in candidates:
force_remove(item)
def force_remove(item):
if path.isfile(item):
os.remove(item)
return
if path.isdir(item):
shutil.rmtree(item)
return
if __name__ == '__main__':
main()
#!/usr/bin/env ruby
require 'fileutils'
# カレントディレクトリにあるファイル一覧
files = Dir::entries(Dir::pwd)
files.select!{|f|
# 実行可能ファイルである
if FileTest::file?(f) && FileTest::executable?(f)
true
# '.dSYM'で終わるディレクトリである
elsif FileTest::directory?(f) && /\.dSYM$/ =~ f
true
else
false
end
}
# 確認画面の表示
$stderr.puts "candidates for delete"
$stderr.puts "----------"
files.each do |f|
$stderr.puts f
end
$stderr.puts "----------"
$stderr.print "delete all? (y/n [n]) "
# 削除の処理
input = gets
if input && input.chomp == 'y'
files.each do |f|
FileUtils.rm_rf(f)
end
$stderr.puts "file deleted"
else
$stderr.puts "not deleted"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment