fork download
  1. import os, re, shutil, sys, time
  2.  
  3. start = time.time()
  4. lst_file = 'list2.txt'
  5. #lst_file = sys.argv[1]
  6. search_dir = "./dir"
  7. #search_dir = sys.argv[2]
  8. tag_dir = os.path.expandvars('$HOME') + "/Desktop/tmp/"
  9.  
  10. def search_file(dir_name):
  11. num_files = 0
  12. for dirPath, dirNames, fileNames in os.walk(dir_name):
  13. for f in fileNames:
  14. num_files += 1
  15. basename = os.path.splitext(f)[0]
  16. if line == basename:
  17. print "finded >>", os.path.join(dirPath, f)
  18. old = os.path.join(dirPath, f)
  19. new = tag_dir + f
  20. shutil.copy(old, new)
  21. return num_files
  22.  
  23. if not os.path.isdir(tag_dir):
  24. os.mkdir(tag_dir)
  25.  
  26. num_files = 0
  27. with open(lst_file) as f:
  28. for line in f.readlines():
  29. line = line[:-1]
  30. num_files = search_file(search_dir)
  31. #print "-----print dict list-----"
  32. #print(dict.items())
  33. #print
  34. print "Total search files:", num_files
  35. end = time.time()
  36. print "Elapsed time:", end - start
Runtime error #stdin #stdout #stderr 0.01s 7788KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 24, in <module>
OSError: [Errno 2] No such file or directory: '/home/UnEagD/Desktop/tmp/'