testfolder (my root folder)
test1folder 2xls 4doc files
test2folder 7xls files
test3dolder 5doc files
test4folder
test5folder 3 doc files
script find xls or doc count rename folder rename result
test1folder_ 2xls_ 4doc
test2folder_7xls
test3dolder_5doc
test4folder (no rename)
test5folder_3doc
too diffucult script , who can ?
please help
Sincerely
rename folder search result ...
rename folder search result ...
newbie or not...........
Re: rename folder search result ...
foreach loop
listfolder()
gettoken() with "count"
rename()
Have fun
listfolder()
gettoken() with "count"
rename()
Have fun
One of my scripts helped you out? Please donate via Paypal
Re: rename folder search result ...
im newbie but u re prof.
thanks for help dear.
i will try ....
thanks for help dear.
i will try ....
newbie or not...........
Re: rename folder search result ...
Hi drjs5x, I 'd like to help.
Here is my way to figure it out. The files listed in a folder maybe in a random order, so I first go to that folder and sort all the files by Exts and then select all of them. It seems that after that sort and select the job can be done much easier.
Thank you very much for your guidance, I understood foreach loop and listfolder(), but I can not figure out how to gettoken() with "count". I do not know how to get differet exts from the string and count them, a K.M.P.?foreach loop
listfolder()
gettoken() with "count"
rename()
Have fun
Here is my way to figure it out. The files listed in a folder maybe in a random order, so I first go to that folder and sort all the files by Exts and then select all of them. It seems that after that sort and select the job can be done much easier.
Code: Select all
$sels = get('SelectedItemsPathNames', '|', 'a');
$res = 0;
foreach($i, $sels)
{
if (exists($i) != 2) {continue;}
$res = 1;
goto $i;
sortby "ext";
sel f;
$sels2 = get('SelectedItemsNames', '|', 'a');
$before = "....";
$result = "";
$count = 0;
$cur = "";
foreach($j, $sels2, , "No file.")
{
if(gettoken($j, "count", ".") > 1)
{
$cur = gettoken($j, -1, ".");
}
if(($cur != $before) && ($before != "...."))
{
$result = $result.$count.$before."_";
$before = $cur;
$count = 0;
} elseif ($before == "....")
{
$before = $cur;
}
$count++;
}
if($count != 0)
{
$result = $result.$count.$cur;
renameitem("*_$result", $i);
}
}
if ($res)
{
goto "<curpath>\..";
msg "Job done.";
}
else
{
msg "No folder.";
}
Last edited by shpkong on 15 Jan 2017 10:58, edited 3 times in total.
Re: rename folder search result ...
This script support multi folders.
Just select some folders and the script will do all the job for you.
Maybe not fast enough...
Just select some folders and the script will do all the job for you.
Maybe not fast enough...
Re: rename folder search result ...
Hi, drjs5x
You only want to count .xls and .doc, right?
Maybe I am over-anxious...
My slow script can support any file type under a folder.
If only xls or doc, I think gettoken() with "count" can do the job.
You only want to count .xls and .doc, right?
Maybe I am over-anxious...
My slow script can support any file type under a folder.
If only xls or doc, I think gettoken() with "count" can do the job.
Re: rename folder search result ...
Code: Select all
$sels = get('SelectedItemsPathNames', '|', 'a');
$res = 0;
foreach($i, $sels)
{
if (exists($i) != 2) {continue;}
$res = 1;
$list = listfolder($i);
$a = 0;
$b = 0;
if(gettoken($list, "count", ".xls") > 1)
{
$a = 1;
$count_xls = gettoken($list, "count", ".xls") - 1;
$xls = $count_xls."xls";
}
if(gettoken($list, "count", ".doc") > 1)
{
$b = 1;
$count_doc = gettoken($list, "count", ".doc") - 1;
$doc = $count_doc."doc";
}
if($a && !$b) {renameitem("*_$xls", $i);}
if(!$a && $b) {renameitem("*_$doc", $i);}
if($a && $b) {$result = $xls."_".$doc;renameitem("*_$result", $i);}
}
if ($res)
{
msg "Job done.";
}
else
{
msg "No folder.";
}
Note2: If some file names under the selected folder also contain .xls or .doc, this script return wrong answer.
Re: rename folder search result ...
The thing is, if you want it to work on any subfolder structure you should rename the deepest nested ones first...
So, this should be rather fast (about half a second on a structure with 2000 files in 612 folders with about 20 doc
and 5 xls files). Test conducted with a ram disk to rule out slow hdd drives if you don't use ssds...
So, this should be rather fast (about half a second on a structure with 2000 files in 612 folders with about 20 doc
and 5 xls files). Test conducted with a ram disk to rule out slow hdd drives if you don't use ssds...
Code: Select all
$exts = "*.doc;*.xls";
$result = quicksearch($exts, get("SelectedItemsPathNames", ";"));
$sorted = FolderDepthSort($result);
$renamed = "";
while ($sorted) {
$line = gettoken($sorted, 1, <crlf>);
$ext = gpc($line, "ext");
$path = gpc($line, "path");
$pattern = regexreplace("$path", "(#|\[)", "[$1]");
$samePaths = formatlist($sorted, "ef", <crlf>, "$pattern\*");
$docCnt = gettoken(regexmatches($samePaths, "\.doc$"), "count", "|");
$xlsCnt = gettoken(regexmatches($samePaths, "\.xls$"), "count", "|");
$sorted = formatlist($sorted, "ef", <crlf>, "!" . regexreplace($samePaths, "(#|\[)", "[$1]"));
$allPrefix = (($docCnt) ? "_$docCnt" . "doc" : "") . (($xlsCnt) ? "_$xlsCnt" . "xls" : "");
$renamed = $renamed . "From: $path<crlf>To : $path$allPrefix" . <crlf 2>;
rename "b", "*$allPrefix", , $path;
}
if ($renamed) { text "Rename operation(s) executed:<crlf 2>$renamed"; }
else { msg "No folders with $exts found..."; }
function FolderDepthSort($list, $inDelim="<crlf>", $outDelim="<crlf>") {
$result = "";
foreach($item, $list, $inDelim, "e") {
$count = gettoken($item, "count", "\");
if ($count >= $lastCount) { $result = $item . $outDelim . $result; }
else { $result = $result . $outDelim . $item; }
$lastCount = $count;
}
return formatlist($result, "e", $outDelim);
}
One of my scripts helped you out? Please donate via Paypal