Renaming each child with the name of its parent

I have a folder (A) containing sub-folders (B). Each sub-folder contains only one file - that being a video file. The file name for each video file is rather nondescript because it is abbreviated. All the useful information is in the title of the sub-folder containing its video. I feel this is too much overhead. I want to rename each video with the name of its parent folder (B), and get rid of all the sub-folders (B) and let the video’s become the direct child of the main folder (A). It would be like getting rid of the middle-man. Is this something that keyboard maestro could do? I imagine it would have something to do with collections.

Try this:


Rename Files Based on Parent Folder Names [draft].kmmacros (5.9 KB)


Before:

After:



Please note that this is a draft. Its purpose is to show you the basic idea how it can be done. The macro doesn’t do any error checking (though empty folders are handled fine). So please try it first on a test folder!

2 Likes

EDIT: Removed. See below.

Hi Dan,

somehow your variant doesn’t give me the expected result:

Before:

After:

If I read the OP correctly he wanted the new video file names to be the ones from the enclosing subfolders. (See the small screenshots in my first post.)

Yes, of course you’re correct. Thanks.

Edit: Removed. See below.

Tom -

Boy did I screw that one up. I obviously didn’t look that closely, but I thought your post was actually from him, saying it should work “something like this”. I never would have even bothered writing my version had I realized you had posted a response.

In my defense I hadn’t had my morning caffeine yet. :slight_smile:

Also, I’m truly sorry if I offended you - I could easily imagine you viewing my post as saying I didn’t think you knew what you were doing. That’s not the case at all - I know you’ve been using KM a lot longer than I have, or at least, you’ve been active on the forum longer than I have.

It was just me being inattentive, and anyone who knows me would tell you that’s not unusual. Sigh.

1 Like

No problem, no offense taken :slight_smile: I thought you wanted to offer an alternative…

I just was about to ask you if my macro doesn’t work for you at all :wink:

Your last version was a bit closer, but still some problems:

  • names from subfolder are appended to name of main folder (see screenshot)
  • files get thrown out of main directory (see screenshot)
  • macro chokes on empty folders

LOL. OK, I’ll quit while I’m behind. Must not be my day.

On the plus side, you’re obviously a good tester. Anytime you want to find these kinds of bugs in the Macro Import Manager I posted earlier, go for it! I need someone thorough to look at it. I’m too close to it to think of all the scenarios to test. :slight_smile:

1 Like

Hey, on a Sunday this is still a good hour to go back to bed again (assuming you are in the US) :wink:

1 Like

I am indeed in the US (Southern California), but I’m up to watch the British Open. - Watching delayed, on TiVo, so don’t ruin it for me. :slight_smile:

1 Like

I just got back from work and read the back and forth. Man, you guys are impressive.

Jim.

4 Likes