前々から欲しいと思ってたので書いた。
わざわざpythonで書く必要はないんだけど自己満。
気が向いたらモジュール化してみる^_^
# -*- coding: utf-8 -*- import os import os.path import sys import shutil class S(object): def __init__(self): file = os.listdir(os.getcwd()) fl = [] for root in file: if root.endswith(".py"): #コピーしたいファイルの拡張子 fl.append(root) index = fl.index("fc.py") #このファイルの名前 del fl[index] self.count = fl def dir(self): dir_name = "/py_file" #コピー先ディレクトリ名。すでに存在してればそのまま。なければ新しく作ります mk = dir_name.split("/")[1] isd = os.path.isdir(os.getcwd()+dir_name) if isd: print "そのディレクトリはもうあります" else: os.mkdir(mk) return dir_name def fc(self,n): a = self.count u = os.getcwd()+n num = len(a) if num == 0: print "ファイルはありません" return False else: print a for g in range(num): shutil.copy2(a[g],u) return True def select(self,wh): if wh == "y": for kf in self.count: os.remove(kf) print "copy元を削除しました" elif wh == "n": print "copy元はそのままです" else: print "yかnです" def dialog(self,t): if t == True: ans = raw_input("copy元消す? y-n\n") self.select(ans) else: print "コピーに失敗しました" if __name__ == '__main__': r = S() o = r.dir() t = r.fc(o) r.dialog(t)