Skip to content

Commit

Permalink
Fixed this version, now defaults to current directory or accepts a sp…
Browse files Browse the repository at this point in the history
…ecific directory
  • Loading branch information
JosephTLyons committed Aug 3, 2018
1 parent ecb84e4 commit f3a2cdc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions FileOrganizer.py
Expand Up @@ -12,7 +12,7 @@
else:
for subdir, dirs, files in os.walk (currentDirectory):
for file in files:
if os.path.isfile (file):
if os.path.isfile (os.path.join (currentDirectory, file)):
# If file is THIS file, skip
if os.path.basename (__file__) != file:
# Ignore hidden files
Expand All @@ -22,7 +22,7 @@
# Check to make sure file has an exension (if not, its an empty string)
if (len (extension) <= 0):
extension = "MISC"
if not os.path.exists (extension):
os.mkdir (extension)
if not os.path.exists (os.path.join (currentDirectory, extension)):
os.mkdir (os.path.join (currentDirectory, extension))

This comment has been minimized.

Copy link
@codeguru42

codeguru42 Aug 5, 2018

Avoid a function call by assigning intermediate result to a variable:

dir_name = os.path.join (currentDirectory, extension)
if no os.path.exists(dir_name):
    os.mkdir(dir_name)

This comment has been minimized.

Copy link
@JosephTLyons

JosephTLyons Aug 5, 2018

Author Owner

Thank you very much. This was something I was considering doing.

os.rename (os.path.join (currentDirectory, file),
os.path.join (currentDirectory, extension, file))

This comment has been minimized.

Copy link
@codeguru42

codeguru42 Aug 5, 2018

This can be made more readable by assigning intermediate results to variables:

old_file = os.path.join(currentDirectory, file)
new_file = os.path.join(dir_name, file) # assuming previous comment that declares dir_name
os.rename(old_file, new_file)

This comment has been minimized.

Copy link
@JosephTLyons

JosephTLyons Aug 5, 2018

Author Owner

I was riding the line on this choice, but opted not to to reduce the amount of variables used (a trivial optimization), but I might reconsider this as I really try to make code readable in the languages I prefer to use (I'm rather new to Python).

This comment has been minimized.

Copy link
@codeguru42

codeguru42 Aug 5, 2018

In your original version, the interpreter must create a temporary anyway, so the same amount of memory will be used in both cases.

This comment has been minimized.

Copy link
@JosephTLyons

JosephTLyons Aug 7, 2018

Author Owner

Thanks again for the review comments! I added a few commits and took some of your advice.

0 comments on commit f3a2cdc

Please sign in to comment.