yruen / Texture-Filterer

A collection of Python scripts to organize texture dumps in various ways
MIT License
2 stars 0 forks source link

Make error message for rmdir better #35

Closed yruen closed 2 years ago

yruen commented 2 years ago

https://github.com/yruen/Texture-Filterer/blob/d1ef041b52d2bebd568c917a1abe1d7dff5af6b6/other_scripts/otherUtils.py#L38

nikhilnarla commented 2 years ago

Hi @yruen , Are you looking for something like this?

try: error = os.rmdir(dir) except: print("An exception has occurred while trying to delete the directory : " ,dir) print("Exception class : ", sys.exc_info()[0]) print("Exception message : ", sys.exc_info()[1])

yruen commented 2 years ago

@nikhilnarla thank you for your suggestion,

I was thinking more of it catching the error if it detects there are still files in the folder that way it'd print out something like "Could not delete: folder is not empty" but thank you

nikhilnarla commented 2 years ago

Hi @yruen, I guess it is better to have a generic representation for any error that might occur. Also, the above code prints out the following in case of the folder containing some files:

An exception has occurred while trying to delete the directory: C:\Test Exception class : <class 'OSError'> Exception message : [WinError 145] The directory is not empty: 'C:\Test'

yruen commented 2 years ago

@nikhilnarla that's a very valid point. I did not consider that. Thank you for your comment, I'll use this as a base

yruen commented 2 years ago

At the end I just decided to do this since I didn't feel like importing the sys module. But thank you for your interest in my little project, even if it was something minor.

try:
    os.rmdir(dir)
except OSError as e:
    if "39" in str(e):
        print(e, ", skipping")
    else:
        print(e)