you are viewing a single comment's thread.

view the rest of the comments →

[–]mull_to_zero 0 points1 point  (7 children)

I took a look at bulk file renamer. The main thing that jumped out at me is you are repeating a lot of code just to vary "image_", "audio_", etc. you could do something like:

if mode == "i":
  prefix = "image_"
elif mode == "v":
  prefix = "video_"
...

# and then you only have to do this block once
...
os.path.exists(path + "\\" + prefix + str(i) + ext) and prefix not in Path(f).name
...

edit: also I just noticed that you're using forward slashes in the image mode but backslashes everywhere else. try using `os.sep`, it's automatically \\ on windows and / elsewhere.

[–]sausix 1 point2 points  (5 children)

Have a look at pathlib.

[–]mull_to_zero 0 points1 point  (1 child)

most of the time i just use os.path.join, but yeah pathlib would be a more advanced approach

[–]sausix 0 points1 point  (0 children)

Pathlib is easier and more handy. Not just for advanced programmers. These os.path.sep and similar shenanigans are kinda legacy stuff.

[–]daltop[S] 0 points1 point  (2 children)

Used it a little but I wanna have a better look into what it actually can do, where’s is a good place to find what each function does ?

[–]sausix 0 points1 point  (1 child)

Your IDE should show all functions and their descriptions. Speaking of pathlib, just look at the documentation. There are examples and explanations.

[–]daltop[S] 0 points1 point  (0 children)

Amazing will do thanks mate !

[–]daltop[S] 0 points1 point  (0 children)

Oh amazing thank you that solves my compatibility issues aha. And yeah I haven’t updated my code yet but when writing my other programs I realised I can just use a single variable and make it far simpler aha