Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. """ List Document Saver
  2.  
  3. Usage : python ListDocSaver.py [options] [pathToRead]
  4.  
  5. Options :
  6.    -p, --path=     The specific path of directory (or unit to read)
  7.    -h, --help      show thi help
  8.    -d              show debugging information while parsing
  9.  
  10. Example :
  11.    ListDocSaver.py -p /home/userName/ write into [definitepath]/ContenutoaaaaMMgg.txt the content of directory and subdirectory
  12.  
  13.  
  14. Visit http://gli-artigli-della-lince.blogspot.com
  15.    
  16. """
  17.  
  18.  
  19. __author__ = "Aldo D'Offizi (aldo.doffizi@gmail.com)"
  20. __version__= "$1.0$"
  21. __date__ = "$Date: 2011/04/26 14:14:00 $"
  22. __copyright__= "Copyright (c) 2011 Aldo D'Offizi"
  23. __licence__= "Python"
  24. import sys
  25. import getopt
  26. import os
  27.  
  28. defaultPath='/home/username/Documenti/DVD-CD/'
  29.  
  30. def main(argv):
  31.  
  32.     try:
  33.         opts, args=getopt.getopt(argv,"hp:d",["help", "path="])
  34.     except getopt.GetoptError:
  35.         usage()
  36.         sys.exit(2)
  37.     for opt, arg in opts:
  38.         if opt in ("-h", "--help"):
  39.             usage()
  40.             sys.exit()
  41.         elif opt == '-d':
  42.             global _debug
  43.             _debug=1
  44.         elif opt in ("-p", "--path"):
  45.             popolaFileLog(arg)
  46.            
  47.    
  48.  
  49.  
  50. def usage():
  51.     print __doc__
  52.  
  53. def popolaFileLog(directoryRif):
  54.     ls=directoryRif.split('/')
  55.     ls.reverse()
  56.    
  57.     pathFile=defaultPath + 'Contenuto%s.txt' % (ls[0])
  58.    
  59.    
  60.     logFile= open(pathFile,'w')
  61.  
  62.     for path, subdirs, files in os.walk(directoryRif):
  63.         for name in files:
  64.             logFile.writelines(os.path.join(path, name))
  65.             logFile.writelines('\n')
  66.  
  67.     logFile.close()
  68.  
  69. if __name__== "__main__":
  70.     main(sys.argv[1:])