Skip to content

Commit

Permalink
renamed more variables
Browse files Browse the repository at this point in the history
  • Loading branch information
vihdutta committed Mar 12, 2021
1 parent 54e028d commit 2a8bebf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
23 changes: 11 additions & 12 deletions asfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,34 @@ def filesnumrenamer(dstname, srcfiles, dstfiles, idfilelist):
def filesidrenamer(dstname, srcfiles, dstfiles):
for root, dirs, files in os.walk(dstname):
for file in os.listdir(dstname):
num = numgenerator(srcfiles, dstfiles)
num = createid(srcfiles, dstfiles)
if '(' in file:
try:
srcrename = file.split('(')[0] + num + file.split('(')[1]
dstrename = file.split('(')[0] + num + file.split('(')[1]
except IndexError:
srcrename = file + num
dstrename = file + num
else:
try:
srcrename = file.split('.')[0] + num + '.' + file.split('.')[1]
dstrename = file.split('.')[0] + num + '.' + file.split('.')[1]
except IndexError:
srcrename = file + num
os.rename(os.path.join(dstname, file), os.path.join(dstname, srcrename))
dstrename = file + num
os.rename(os.path.join(dstname, file), os.path.join(dstname, dstrename))


def dstsort(dstname):
timenow = datetime.now().strftime('%H-%M-%S-%f')#[:-2]
foldername = f'autosort {timenow}'
makenewfolder = os.mkdir(f'{dstname}/{foldername}')
foldername = f'autosort {datetime.now().strftime("%H-%M-%S-%f")}'
os.mkdir(os.path.join(dstname, foldername))
files = [f for f in os.listdir(dstname) if os.path.isfile(os.path.join(dstname, f))]

for file in files:
name, extension = os.path.splitext(file)
newpath = f'{dstname}/{foldername}/{extension}'
newpath = os.path.join(dstname, foldername, extension)
if not os.path.exists(newpath):
os.makedirs(newpath)
shutil.move(os.path.join(dstname, file), os.path.join(dstname, foldername, extension, name+extension))

#f'{dstname}/{foldername}/{extension}/{name}{extension}
def numgenerator(srcfiles, dstfiles):

def createid(srcfiles, dstfiles):
i1 = len(srcfiles) + len(dstfiles)
i2 = int(str(i1) + '0')
return '---' + str(randint(i1, i2))
15 changes: 7 additions & 8 deletions autosort.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from PyQt5.QtWidgets import QFileDialog
from asfuncs import numgenerator, dstsort, filesnumrenamer, filesidrenamer
from asfuncs import createid, dstsort, filesnumrenamer, filesidrenamer

ignoredirs = ('$RECYCLE.BIN', 'System Volume Information')
metadata = False
Expand Down Expand Up @@ -34,18 +34,17 @@ def copyfromdirs(metadata, replace, sortmethod, dstname):
srcfiles.append(file)
for file in files:
if not replace:
num = numgenerator(srcfiles, dstfiles)
try:
srcrename = file.split('.')[0] + num + '.' + file.split('.')[1]
dstrename = file.split('.')[0] + createid(srcfiles, dstfiles) + '.' + file.split('.')[1]
except IndexError:
srcrename = file + num
dstrename = file + createid(srcfiles, dstfiles)
else:
srcrename = file
dstrename = file
if metadata:
shutil.copy2(os.path.join(root, file), os.path.join(dstname, srcrename))
shutil.copy2(os.path.join(root, file), os.path.join(dstname, dstrename))
else:
shutil.copy(os.path.join(root, file), os.path.join(dstname, srcrename))
dstfiles.append(srcrename)
shutil.copy(os.path.join(root, file), os.path.join(dstname, dstrename))
dstfiles.append(dstrename)
tempfilelistlen -= 1
yield f'Copied {file}. {tempfilelistlen} of {len(allsrcfiles)} files remaining.'
if sortmethod == 2:
Expand Down

0 comments on commit 2a8bebf

Please sign in to comment.