|
| 1 | +'''' Multiple extension changer''' |
| 2 | +import time |
| 3 | +from pathlib import Path as p |
| 4 | +import random as rand |
| 5 | +import hashlib |
| 6 | + |
| 7 | + |
| 8 | +def chxten_(files, xten): |
| 9 | + chfile = [] |
| 10 | + for file in files: |
| 11 | + ch_file = file.split('.') |
| 12 | + ch_file = ch_file[0] |
| 13 | + chfile.append(ch_file) |
| 14 | + if len(xten) == len(chfile): |
| 15 | + chxten = [] |
| 16 | + for i in range(len(chfile)): |
| 17 | + ch_xten = chfile[i] + xten[i] |
| 18 | + chxten.append(ch_xten) |
| 19 | + elif len(xten) < len(chfile) and len(xten) != 1: |
| 20 | + chxten = [] |
| 21 | + for i in range(len(xten)): |
| 22 | + ch_xten = chfile[i] + xten[i] |
| 23 | + chxten.append(ch_xten) |
| 24 | + for i in range(1, (len(chfile) + 1) - len(xten)): |
| 25 | + ch_xten = chfile[- + i] + xten[-1] |
| 26 | + chxten.append(ch_xten) |
| 27 | + elif len(xten) == 1: |
| 28 | + chxten = [] |
| 29 | + for i in range(len(chfile)): |
| 30 | + ch_xten = chfile[i] + xten[0] |
| 31 | + chxten.append(ch_xten) |
| 32 | + elif len(xten) > len(chfile): |
| 33 | + chxten = [] |
| 34 | + for i in range(1, (len(xten) + 1) - len(chfile)): |
| 35 | + f = p(files[-i]) |
| 36 | + p.touch(chfile[-i] + xten[-1]) |
| 37 | + new = f.read_bytes() |
| 38 | + p(chfile[-i] + xten[-1]).write_bytes(new) |
| 39 | + for i in range(len(chfile)): |
| 40 | + ch_xten = chfile[i] + xten[i] |
| 41 | + chxten.append(ch_xten) |
| 42 | + else: |
| 43 | + return 'an error occured' |
| 44 | + return chxten |
| 45 | + |
| 46 | + |
| 47 | +# End of function definitions |
| 48 | +# Beggining of execution of code |
| 49 | +#password |
| 50 | +password = input('Enter password:') |
| 51 | + |
| 52 | +password = password.encode() |
| 53 | + |
| 54 | +password = hashlib.sha512(password).hexdigest() |
| 55 | +if password == 'c99d3d8f321ff63c2f4aaec6f96f8df740efa2dc5f98fccdbbb503627fd69a9084073574ee4df2b888f9fe2ed90e29002c318be476bb62dabf8386a607db06c4': |
| 56 | + pass |
| 57 | +else: |
| 58 | + print('wrong password!') |
| 59 | + time.sleep(0.3) |
| 60 | + exit(404) |
| 61 | +files = input('Enter file names and thier extensions (seperated by commas):') |
| 62 | +xten = input('Enter Xtensions to change with (seperated by commas):') |
| 63 | + |
| 64 | +if files == '*': |
| 65 | + pw = p.cwd() |
| 66 | + files = '' |
| 67 | + for i in pw.iterdir(): |
| 68 | + if not p.is_dir(i): |
| 69 | + i = str(i) |
| 70 | + if not i.endswith('.py'): |
| 71 | + # if not i.endswith('exe'): |
| 72 | + if not i.endswith('.log'): |
| 73 | + files = files + i + ',' |
| 74 | +if files == 'r': |
| 75 | + pw = p.cwd() |
| 76 | + files = '' |
| 77 | + filer = [] |
| 78 | + for i in pw.iterdir(): |
| 79 | + if p.is_file(i): |
| 80 | + i = str(i) |
| 81 | + if not i.endswith('.py'): |
| 82 | + if not i.endswith('.exe'): |
| 83 | + if not i.endswith('.log'): |
| 84 | + filer.append(i) |
| 85 | + for i in range(5): |
| 86 | + pos = rand.randint(0,len(filer)) |
| 87 | + files = files + filer[pos] + ',' |
| 88 | + |
| 89 | + print(files) |
| 90 | +files = files.split(',') |
| 91 | +xten = xten.split(',') |
| 92 | + |
| 93 | +# Validation |
| 94 | +for file in files: |
| 95 | + check = p(file).exists() |
| 96 | + if check == False: |
| 97 | + print(f'{file} is not found. Paste this file in the directory of {file}') |
| 98 | + files.remove(file) |
| 99 | +# Ended validation |
| 100 | + |
| 101 | +count = len(files) |
| 102 | +chxten = chxten_(files, xten) |
| 103 | + |
| 104 | +# Error Handlings |
| 105 | +if chxten == 'an error occured': |
| 106 | + print('Check your inputs correctly') |
| 107 | + time.sleep(1) |
| 108 | + exit(404) |
| 109 | +else: |
| 110 | + try: |
| 111 | + for i in range(len(files)): |
| 112 | + f = p(files[i]) |
| 113 | + f.rename(chxten[i]) |
| 114 | + print('All files has been changed') |
| 115 | + except PermissionError: |
| 116 | + pass |
| 117 | + except FileNotFoundError: |
| 118 | + # Validation |
| 119 | + for file in files: |
| 120 | + check = p(file).exists() |
| 121 | + if check == False: |
| 122 | + print(f'{file} is not found. Paste this file in the directory of {file}') |
| 123 | + files.remove(file) |
| 124 | + # except Exception: |
| 125 | + # print('An Error Has Occured in exception') |
| 126 | + # time.sleep(1) |
| 127 | + # exit(404) |
| 128 | + |
| 129 | +# last modified 3:25PM 12/12/2023 (DD/MM/YYYY) |
0 commit comments