1 (edited by daffdaemon 2014-10-04 01:56:14)

Topic: Rename Folder Based on Content

Renaming files based on folder names is easy using %p and its variants.
Renaming folders based on the files in the folder is quite difficult.

ie:
pictures\1\bob01.jpg         -> pictures\Bob\bob01.jpg
pictures\2\mary01.jpg       -> pictures\Mary\mary01.jpg   
pictures\3\sam01.jpg        -> pictures\Sam\sam01.jpg

A variable that reported directory contents would be very useful here.
Something like %k{line,path,param,ext}
Where:
Line=Line # from dir command output (ie 1,2,-1,-2,etc) Default=1
Path=standard path specification Default=path of current selection
Param=standard DIR command parameters Default=/A:-d-h-s /B /On
Ext=File Extension On/Off Switch Default=OFF (ie. strip file extension from line)

Once the string was returned it would be fairly easy using standard operations to rename according to preference.
Using the above example with folders 1,2,3 etc selected
  %Uk(s/([a-z]+)\d.*/\1/i) would give the result shown, as would %Uk(1,-2), etc.

Line = 0 could return entire dir command output for parsing by regex.

Re: Rename Folder Based on Content

Hello,

This is an interesting question.
I may have an idea to achieve it but it needs some code modifications.
I'll try to add it in a new release.

Thanks

Re: Rename Folder Based on Content

I looked around a bit. There's nothing I could find that does anything like this.

I would be interested in hearing what ideas you've got, if you want to kick it around a bit.

Re: Rename Folder Based on Content

Before going further : isn't there any name pattern for the files in the directories to rename ?
For example :
1\bob01.jpg
1\bob02.jpg
1\bob03.jpg

Can you give a more complete example ? (from and to)

Re: Rename Folder Based on Content

In the case that prompted me to make the suggestion there was a simple name pattern.
I had over 500 folders; each identified with just a nondescript number. Inside each folder was 1 to many files with a name and a number, just as in your example,  although the separator varied. Each folder is name segregated although there are duplicates across folders. The %nc variable would sort that out though.

Of course this is the most straightforward case. As I thought about it it seemed that if one approached the idea more generally there might be many variations.
Examples:
Rename folder based on first and last file in the folder
Rename based on earliest or latest date of files in the folder, or both.

I am not a Regex expert but it also seemed to me that if a folder contained a bunch of files that didn't fit a pattern but if each folder contained at least one file that did match a pattern that a multiline regex search could grab the desired info.

OK, That one's maybe a stretch.

But it seems to me that if you make it generic enough, who know what ways people will figure out how to use it?

Re: Rename Folder Based on Content

Siren doesn't have a "search for file" expression function.
What I imagined was that, while in "tree mode", the first selected file of each sub-folder could be the naming source.
This selection would have to be done manually or with other selection options.
This feature is not present yet and would need work to be correctly implemented.

Re: Rename Folder Based on Content

Well, I know you don't have a search for file function. But when your in tree mode you can't see the files in subfolders unless you manually open each one. And manually selecting naming source would defeat the purpose.

I was thinking of a call out to the DOS DIR command function. The command would return a bunch of text formatted according to the parameters sent from the Path & Param variables.
You would have to write a little routine to pull out the correct line # based on the Line variable.
That line (or lines) of text gets returned to the user in the %k variable.
After that its up to the user to parse the text using regex's or your standard modifiers.

So I'm in a directory that has a bunch of variously named sub-folders, but each sub-folder contains a set of files with well ordered file names. I select all the sub-folders and for each selected folder the program gets a dir listing, selects the requested line of text from that listing, and returns that line of text for parsing according to the modifiers.

Re: Rename Folder Based on Content

Hello,

Sorry for my late reply.
To be honest I don't think Siren is the right tool to achieve this.
A renamer integrating a scripting language in the process should fit your needs.
I know that some excellent ones of this kind exist.
You should have a look to them.

Regards.

Re: Rename Folder Based on Content

I just wanted to add a note here for those interested in this topic. While discussing another topic we came up with a solution that works pretty well here.
Example: I have a bunch of folders with non-descript names but the 1st file in each folder is a cover with a name in the form of "Date - Artist - Album.jpg"

step 1: for /D %i in (*) do @(dir /b /a-d /on "%i" > "%i\dirfiles.txt")   ;;run from cmd prompt OR
            cmd /C \"dir /b /a-d \"%f\" > \"%f\\dirfiles.txt\"\"                    ;;run on highlighted folders fom Siren Tools
step 2: %T{%fa(s/$/\\dirfiles.txt/),1};%b
step 3: for /D %i in (*) do @(del "%i\dirfiles.txt")          ;;run from cmd prompt OR
            cmd /C \"del \"%f\\dirfiles.txt\"\"                       ;; run on highlighted folders from Siren Tools

A variety of outcomes can be accomplished here by simple variations on the command parameters passed to the DIR command and by post-processing of the selected text line returned by %T