Advertisement
Guest User

MANDR1K

a guest
Jan 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. import os
  4. import sys
  5. import psutil
  6. import shutil
  7.  
  8.  
  9. def duplicate_file(filename):
  10. if os.path.isfile(filename):
  11. newfile = filename + '.dupl' # to concat
  12. shutil.copy(filename, newfile)
  13. if os.path.exists(newfile):
  14. print('</> File ', newfile, ' created successfully')
  15. return True
  16. else:
  17. print('</> Oh, some copy error')
  18. return False
  19.  
  20.  
  21. def del_duplicates(dirname):
  22. file_list = os.listdir(dirname)
  23. dupl_count = 0
  24. for f in file_list:
  25. fullname = os.path.join(dirname, f) # \ /
  26. if fullname.endswith('.dupl'):
  27. os.remove(fullname)
  28. if not os.path.exists(fullname):
  29. dupl_count += 1
  30. print('</> File ', fullname, ' removed successfully')
  31. return dupl_count
  32.  
  33.  
  34.  
  35.  
  36. def sys_info():
  37. print('</> So I know this info about your system: ')
  38. print('</> Number of processes: ', psutil.cpu_count())
  39. print('</> The platform: ', sys.platform)
  40. print('</> The system encoding: ', sys.getfilesystemencoding())
  41. print('</> Current directory: ', os.getcwd())
  42.  
  43.  
  44. print('</> Hello, my name is bot Jack and I am your computer assistant')
  45. answer = ''
  46.  
  47. while answer != 'q':
  48. answer = input('</> Would u like to know smth new about your system? (y/n/q)')
  49. if answer == 'y':
  50. print('</> Alright')
  51. print('</> I can do that:')
  52. print('--> [1] - display the file list')
  53. print('--> [2] - display the system information')
  54. print('--> [3] - display the processes list')
  55. print('--> [4] - make duplicates in current directory')
  56. print('--> [5] - make duplicate of the select file')
  57. print('--> [6] - delete duplicates in current directory')
  58. do = int(input('</> Select the option: '))
  59.  
  60. if do == 1:
  61. print(os.listdir())
  62.  
  63. elif do == 2:
  64. sys_info()
  65.  
  66. elif do == 3:
  67. print(psutil.pids())
  68.  
  69. elif do == 4:
  70. print('</> Making some magic with duplications in current directory..')
  71. file_list = os.listdir()
  72. i = 0
  73. while i < len(file_list):
  74. duplicate_file(file_list[i])
  75. i += 1
  76.  
  77. elif do == 5:
  78. print('</> Making some magic with duplication of the select file in current directory..')
  79. filename = input('</> Input the file name u want to duplicate: ')
  80. duplicate_file(filename)
  81.  
  82. elif do == 6:
  83. print('</> Making some magic with removing duplications in current directory..')
  84. dirname = input('</> Input the directory name: ')
  85. count = del_duplicates(dirname)
  86. print('--> Number of removed duplicates: ', count)
  87.  
  88. else:
  89. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement