Page 2 of 3

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 17 Aug 2015 20:44
by highend
but I'm having trouble getting this to work
What exactly isn't working?

By the way, since we have the quicksearch() function, the script can be made a bit faster by replacing

Code: Select all

$allFiles  = folderreport("files", "r", "<curpath>", "r", , "|");
with

Code: Select all

$allFiles  = quicksearch("* /f", "<curpath>", "|");

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 17 Aug 2015 21:18
by hermhart
For some reason it just hangs. I have a very small structure that I'm testing it with. It has a total of about 6 folders and 7 files scattered in them.

My exact code (with the replacement you suggested is:

Code: Select all

msg "Flatten then recycle all sub-folders to currently selected tree item?", 1;
    setting "BackgroundFileOps", 0;
    $filesRoot = listfolder("<curpath>", , 1);
    $foldersRoot = listfolder("<curpath>", , 2);
    //$allFiles  = folderreport("files", "r", "<curpath>", "r", , "|");
    $allFiles  = quicksearch("* /f", "<curpath>", "|");
    $filesInSubfolders = formatlist(replacelist($allFiles, $filesRoot, "", "|"), "dents");
    backupto "<curpath>", $filesInSubfolders, 4, , 0, 0, 0, 0, 0;
    delete 1, 0, $foldersRoot;

    msg "All files flattened.";

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 17 Aug 2015 21:25
by highend
Just hangs...

Download: <removed>

and send me a PM with the ID after you've started it...

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 17 Aug 2015 21:29
by hermhart
Sadly, I will not be able to do that from work. They have that blocked. Thank you though. I appreciate you getting back with me so quickly.

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 17 Aug 2015 21:33
by highend
Then you have to debug it yourself...

Add this line (indented, please!)

Code: Select all

step;
just over

Code: Select all

$filesRoot = listfolder("<curpath>", , 1);
and run it again. Where exactly does it hang now?


For all, another major speedup (but only do this if you files / folders don't have "# or [" in their names)...

Code: Select all

$filesInSubfolders = formatlist(replacelist($allFiles, $filesRoot, "", "|"), "dents");
The replacelist is incredible slow if the number of files is growing...

Replace it with:

Code: Select all

$filesInSubfolders = formatlist($allFiles, "dentsf", $sep, regexreplace("!$filesRoot", "([#[])", "[$1]"));
1000 files in the root folder and 1000 files in a subfolder:
Old version: Minutes
New version: Under one second

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 18 Aug 2015 13:41
by hermhart
It seems that the line that was causing the problem was:

Code: Select all

$filesInSubfolders = formatlist(replacelist($allFiles, $filesRoot, "", "|"), "dents");
I replaced it with the new line that you suggested:

Code: Select all

$filesInSubfolders = formatlist($allFiles, "dentsf", "|", "!$filesRoot");
and it seems to work quite good now.

I know you said that you shouldn't use this new line if your names have "#, [ or ]" in their names. None of my files/folders have that, but is there something that would work if that case comes around?

Thanks a ton!

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 18 Aug 2015 13:58
by highend
None of my files/folders have that, but is there something that would work if that case comes around?

Code: Select all

$filesInSubfolders = formatlist($allFiles, "dentsf", $sep, regexreplace("!$filesRoot", "([#[])", "[$1]"));

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 18 Aug 2015 14:05
by hermhart
highend,

Thank you so much for the help!

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:22
by yusef88
stupid question:what does flatten folder do exactly i selected folder to flatten from tree menu and didn't see any changes?

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:37
by highend
Any now we're guessing which script you've used?

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:44
by yusef88
highend wrote:Any now we're guessing which script you've used?
if you mean me 8) i used tree context menu

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:49
by highend
That command asks for a confirmation before it starts, did you see that? Apart from that it: it works fine with the current beta...

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:51
by bdeshi
It flattens the selected folder. All subfolder contents are moved to the root, that is, the selected folder in this case.

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 26 Aug 2015 15:57
by yusef88
so the selected folder must contains at least one sub folder-not only files-to do its job,thanks :tup:

Re: Folder Flatten & Segregate script - Has anyone...?

Posted: 31 Aug 2015 09:13
by starstuff
Hi highend,

would it be possible to include a check if there is more than 1 item inside the folder then it wont process the folder and jump to the next folder?

if example a folder contains 2 files or 1 file and 1 folder or 2 folders, it will skip this folder

Thank You!