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

Discuss and share scripts and script files...
highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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>", "|");
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 240
Joined: 13 Jan 2015 18:41

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

Post 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.";
Windows 11 Pro; 100% scaling

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post by highend »

Just hangs...

Download: <removed>

and send me a PM with the ID after you've started it...
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 240
Joined: 13 Jan 2015 18:41

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

Post 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.
Windows 11 Pro; 100% scaling

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 240
Joined: 13 Jan 2015 18:41

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

Post 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!
Windows 11 Pro; 100% scaling

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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]"));
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 240
Joined: 13 Jan 2015 18:41

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

Post by hermhart »

highend,

Thank you so much for the help!
Windows 11 Pro; 100% scaling

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

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

Post by yusef88 »

stupid question:what does flatten folder do exactly i selected folder to flatten from tree menu and didn't see any changes?

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post by highend »

Any now we're guessing which script you've used?
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

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

Post by yusef88 »

highend wrote:Any now we're guessing which script you've used?
if you mean me 8) i used tree context menu
Attachments
2015-08-26_154229.png
2015-08-26_154229.png (11.01 KiB) Viewed 3390 times

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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...
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

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

Post by bdeshi »

It flattens the selected folder. All subfolder contents are moved to the root, that is, the selected folder in this case.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

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

Post by yusef88 »

so the selected folder must contains at least one sub folder-not only files-to do its job,thanks :tup:

starstuff
Posts: 29
Joined: 07 May 2015 15:30

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

Post 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!

Post Reply