rename largest file with folder name

A swapping-ground for Regular Expression syntax

rename largest file with folder name

Postby mkeithddc » Sat Apr 19, 2014 7:12 pm

OK, so I have thousands of folders spanning multiple drives. For some reason the folders have the proper name
that I want for the media file thats in the folder. now 99 percent of the time there is only one media file in each
folder, and also the largest file. so what I want is some kind of way to copy and paste the entire folder name and
paste it to the largest file in that folder. of course this needs to work with subfolders so i can choose at least one
whole drive at a time and get all the folders in that drive,

this is probably not possible, or would need a whole program written, at least I cant think of how to even do it, but
I am not good with these expression, in fact most of what I have seen on this board leaves me scratching my head, lol.

so if some really nice super smart person can help me out, that would be sweet, thanks in advance11
mkeithddc
 
Posts: 1
Joined: Sat Apr 19, 2014 7:02 pm

Rename LargestFile to ParDirName

Postby truth » Sun Apr 20, 2014 2:02 pm

BRU's regex only matches filename-chars (not size-attributes/etc).
It could be written otherwise, but greatly reducing bulk-rename-speeds.
Regex cant set a max/min #FilesPerDir to process, that requires an additional setting.

For those with sed in their arsenal, run below from root:
for /f "delims=" %a in ('dir /b/s/ad') do @dir /b/s/o-s/a-d "%a"|sed -r -n "1s/.*\\(.*)\\.*(\..*)/REN \x22&\x22 \x22\1\2\x22/p"|sed e

Be warned: it renames the largest-file in each directory to its ParentDirName!
No part of OrigName is kept (besides the .extension)

If a backup-list of largest-names is needed, 1st run below from root:
for /f "delims=" %a in ('dir /b/s/ad') do @dir /b/s/o-s/a-d "%a"|sed -n 1p>>OrigNames.txt

There are slower, graphical apps, to handle this as well.
Just know that regex merely matches text-conditions, it wont set a max/min #FilesPerDir to process.
That requires an entirely different setting, apart from regex (regardless of app).
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to Regular Expressions