Multi Commander > Feature Requests and Suggestions
Name as Folder?
Ulfhednar:
Is it possible for me to run a script that would name files as their parent folder? This would be a command I could allocate to a button ideally.
e.g.
\tortoise
file.avi
to
\tortoise
tortoise.avi
or (more tricky)
\Flowers
file01.jpg
file02.jpg
to
\Flowers
Flowers01.jpg
Flowers02.jpg
I can see that I would also need to run a numbering routine in this example unless I can exclude numerals somehow.
Jungle:
You can test the following code. But it doesn't check whether existing names have ending numerals.
Backup your files before testing and perform testing it in the temporary folder.
--- Code: ---Log( 1, 10, "Renaming files to %%parent_folder_name%%[_N].*" );
@var $src_path = GetSourcePath();
@var $arr = PathGetParts( $src_path );
@var $name = $arr[0];
@var $prefix = StrReplace( PathGetPathPart( $src_path, 1 ), $name, "" );
@var $n = StrRFind( $prefix, "\\" );
if ( $n > 0 )
{
$prefix = StrSub( $prefix, $n + 1, StrLen( $prefix ) - $n - 1 );
@var $i;
@var $s;
@var $file;
@var $files;
$arr = GetSourceSelectedPaths();
for ( $i = 0; $i < arrayCount( $arr ); $i++ )
{
$file = $arr[$i];
$s = PathGetFileExtPart( $file );
$name = $prefix + "*" + $s;
$files = FindFiles( $src_path + $name );
$n = arrayCount( $files );
if ( $n == 0 )
{
$s = "";
}
else
{
if ( $n == 1 )
{
$s = $files[0];
RenameFile( $s, StrReplace( $name, "*", "_0" ), "RENAME_RO" );
}
$s = "_" + numtostr( $n );
}
RenameFile( $file, StrReplace( $name, "*", $s ), "RENAME_RO" );
}
}
else
{
Log( 1, 10, "It seems parent folder is root. Renaming impossible." );
}
--- End code ---
Mathias (Author):
Wow.. that was a nice script. +2 :)
If something small is missing to make it more simple let me know.
Jungle:
However i have not tested this script with thousands of files, so i'm not sure about perfomance/resource consumption.
Ulfhednar:
Thanks Jungle for a nice script! :)
I see it contains more functions than just getting & implanting the dir name.
I like the numbering/counter for multiple files of the same type - especially as the numbering allows for pre-existing files of the same name.
The following is worth noting as it could cause issues:-
It isn't exclusive of folders, if I 'accidentally' click a sub-folder it will rename as parent dir also.
When I renamed a bunch of jpgs, it dropped the already present numbers & used it's own counter.
I mention it as something a scripting wizard might consider, an advisory to anyone else trying this & as something I should try & figure out...
For pre-existing numerals - how easy is it to exclude already present numbers? (e.g. as with a regex)
Maybe I'd need a 2nd script...
Not saying you should write me one, just wondering as I want to play around with this but need some pointers. ::) :P
-I must find time to learn this multi-scripting & this is an incentive!!
You have given me a good start to look more closely at the MC scripts & a great new functionality for my MC. ;D
Navigation
[0] Message Index
[#] Next page
Go to full version