0

Is there any built in functionality in python as to rename files smartly in windows.

I am using os.rename to move files to a higher directory.

The problem is, the directory I move the file to could have a file that has the same name. I want to do what windows allows a user to do in the GUI, which is choose to auto-rename the file to "<file>.<ext>(n)" where n is the smallest integer not used already.

Is there any way to do this built in. If not does anyone have code that does this?

Thanks

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by blah32
1

If you are only concerned with functioning in Windows, there is ready possibility, even not built in directly:
Win32 shell: use SHFileOperation:

Finally, the Platinum Option is probably to use the shell functionality which will offer the same facilities as Explorer, including animated icons, the recycle bin and renaming on collision.

Edited by pyTony: n/a

Votes + Comments
Interesting link
0

When I try the code on that page, I get:
from win32com.shell import shell, shellcon
ImportError: No module named win32com.shell

0

Nvm I got it to run.

Is there a way to make it automatically select "keep both" ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.