Odys
Odys

Reputation: 9090

Is it possible to use Windows Api (win7) in order to mass rename files?

While in a folder with lots of files, one can select many and rename only one. This one will get the name NewName (1) and the rest will follow as NewName (2) etc..

Is there a way to use this algorithm?

I mostly interested in using WinApi methods in general. It is easy to implement this specific algorithm. I don't know how to dig into explorer.exe and see what method it uses but probably it would be something reusable.

I mostly use c# but any language example would be accepted.

Upvotes: 2

Views: 186

Answers (3)

user3320715
user3320715

Reputation: 1

Yes it is possible see here http://blog.gadodia.net/stupid-windows-trick-mass-renaming/ I used this to oganized and Number files in mass

Upvotes: 0

Odys
Odys

Reputation: 9090

As pointed out by Remy Lebeau I came up with the official way to do it.

IFileOperation::RenameItems
Declares a set of items that are to be given a new display name.
All items are given the same name.
...
If more than one of the items in the collection at pUnkItems is
in the same folder, the renamed files are appended with a number in
parentheses to differentiate them, for instance newfile(1).txt,
newfile(2).txt, and newfile(3).txt.

Here is the referenced link.

This also answers my question on where to start to using windows shell api to do stuff. The answer is here.

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 595981

Not with a single function call, no. But you can loop through the files one at a time using SHFileOperation() with the FOF_RENAMEONCOLLISION flag to rename each file to the same target filename so Windows will generate its own unique filenames.

Upvotes: 2

Related Questions