Skip to content

Commit

Permalink
added comments to defaultBehavior()
Browse files Browse the repository at this point in the history
  • Loading branch information
rjwignar committed May 18, 2024
1 parent 3f81480 commit 6a07e2a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions folderizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def main():
addFileCategory("videos", videoExtensions)
addFileCategory("textFiles", textExtensions)

# Initialize parser
parser = argparse.ArgumentParser(
prog="folderizer",
description="File organization command-line tool.",
Expand All @@ -45,26 +46,34 @@ def main():
args = parser.parse_args()
print(args, args.filepath, args.default)

# --default subroutine
def defaultBehavior():
# Extract target path from arguments
target_path = os.path.abspath(args.filepath)
# Check if filepath exists
if (os.access(target_path, os.F_OK)):
with os.scandir(target_path) as it:
# Iterate through each non-hidden file in target_path
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
# Extract file extension from entry
fileExtension = os.path.splitext(entry.name)[1]
# Search for extension match in fileCategories
for fileType, properties in fileCategories.items():
if fileExtension in properties['extensions']:
properties['fileCount'] +=1
createFolder(target_path, fileType)
oldPath = os.path.join(target_path, entry.name)
newPath = os.path.join(target_path, fileType, entry.name)
# Move file into appropriate folder
os.rename(oldPath, newPath)
properties['movedCount'] +=1
# Display file(s) found and file(s) moved by fileCategory
dictionarySummary(fileCategories)
else:
print("Filepath doesn't exist")

# --default
if args.default:
defaultBehavior()

Expand Down

0 comments on commit 6a07e2a

Please sign in to comment.