Batch Rename Files to their Parent Folder

Hi there, I'd really appreciate some help with the following issue I'm encountering:

I have a folder [MAIN1], that contains 100 subfolders [SUB1,SUB2...SUB100]. Inside of the subfolders, there are files with random names [IMG1, DOG56, asf7sh0, etc.].

My goal is to batch rename all the files to their parent folder name, and when there is more than one file per folder, have them numbered. So far, I had been using a custom button for similar tasks.

image

My problem is that when I use Flat View to select all the files, and then press the button, a few files get renamed, and then I get this error, interrupting the batch.

image

If I select the file causing the error individually, it works as expected. As long as I only select the files from one folder, there is no error. I've also tried using the search function instead of Flat View, but I get the same result. I've also tried other buttons from the forums, but no luck. Clearly I must have done something wrong when I made the original button, but I'm not sure what it is.

Also, would it be possible to make it so I can select the folders (SUB1...SUB100), and then press a button to have all the files inside name themselves after their parent folder, rather than having to use flatview to select the files?

Thanks, I really appreciate all the help I can get!

If you're selecting everything in Flat View and running that command, it's going to rename the parent folders as well. (It should usually handle that and adjust where it looks for the files, or rename the files first, but maybe something about this specific case confuses it. Could be when the folder ends up clashing with an existing name.)

Assuming you only want to rename the files, you can add TYPE=files to the Rename arguments to skip the folders.

I'd use the Advanced Renamer...

... but if you prefer Flatview and a button, try

Rename TO={filepath|..|nopath|noterm}{file|ext} WHENEXISTS=rename

Thank you for the quick reply! I am specifically not selecting the folders, either by inverting the selection after toggling flatview, or by using the "flat view no folder view". Are those folders still being acted upon?

Ha! I use the advanced renamer every single day, and I never thought to apply it to this situation. I've seen multiple users asking similar questions, and it always came down to buttons. Well, thank you very much for the suggestions, this appears to work great!