how to suck out folder contents recursively

Discuss and share scripts and script files...
Huidong
Posts: 213
Joined: 18 May 2011 21:55

how to suck out folder contents recursively

Post by Huidong »

I tried to make a command that moves all contents of selected folders to the current path, for now the command is very weak

Code: Select all

::moveto "<curpath>", "<curitem>\*"
It can do the job for only one folder (the last selected one), and non-recursively.
Could you please help to make it work for multiple selected folders (batch processing), and do the job recursively, i.e. extracts all contents of all subfolders up to the current path?
One difficulty I encounter is that when using <selitems>, I don't know how to put the \* for each individual selected folder, since <selitems> are all in quotes.
Thanks!

PS Noticed something weird, after running the above command, I'm not allowed to undo the moveto! Why?

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: how to suck out folder contents recursively

Post by zer0 »

Assuming you have your files and folders sorted apart, this shouldn't be too difficult. Here's a script that I came up with:

Code: Select all

while (filetype(<curitem>) == "Nofile") { // if it is a folder, start a loop
   #162; // go into the dir
   #250; // select all
   MoveTo(".."); // move all selected items up a level
   #527; // go up
   delete 1, 0, ":list"; // optional, delete selected folder so that you can move onto the next one
}
Last edited by zer0 on 21 May 2011 01:13, edited 2 times in total.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

Thank you. I tried it but it did not work as desired. It moved subfolders in my test folder up to the the same level as the folder itself (namely out of my folder), while I'd like to just move the subfolder contents to under the folder. Also multiple Windows explorer windows are opened. I wish I can select MULTIPLE folders under a main folder and extract all their contents up to the level that's still under the main folder. Is that possible to do ? Thanks.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

Even I select only one folder and let it loop to the rest folders (I see what you meant in the script now), it did not work, but this time no explorer windows opened, and the subfolders stay under the main folder, but nothing moved up.

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: how to suck out folder contents recursively

Post by zer0 »

OK, this script should do the job then. I tested your desired scenario and it seems to work:

Code: Select all

$filelist = getinfo('SelectedItemsPathNames', '|'). '|';
   $p = strpos($filelist, '|');
   while ($p >= 0)
   {
      $file = substr($filelist, 0, $p);
      $filelist = substr($filelist, $p + 1);
      $p = strpos($filelist, '|');
      moveto "<curpath>", "$file\*";
   }
Last edited by zer0 on 21 May 2011 02:34, edited 1 time in total.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

Wow I can't understand it, but it works! except that it is not recursive, sub-subfolder contents did not get extracted, although the sub-subfolder itself was moved up.
Thank you so much! I will read more to understand it.
Hope you will further improve the script if possible.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

Hi zer0, one question, it appears to me that $name is not used, why's that?

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: how to suck out folder contents recursively

Post by zer0 »

Huidong wrote:except that it is not recursive, sub-subfolder contents did not get extracted, although the sub-subfolder itself was moved up.
I'm not sure what you mean. I tested it with a few folders (with files them) inside of a root folder. Those files were moved to same level as those folders. Isn't that what you wanted?
Huidong wrote:Hi zer0, one question, it appears to me that $name is not used, why's that?
You can disregard it as it was just line that I unnecessarily pasted from another script of mine.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

I mean, it works for one level under the main folder (say "subfolder"), but does not work for two levels under the main folder (I called it "sub-subfolder").

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: how to suck out folder contents recursively

Post by zer0 »

Huidong wrote:I mean, it works for one level under the main folder (say "subfolder"), but does not work for two levels under the main folder (I called it "sub-subfolder").
Now you're piling on additional permutations of complexity that weren't there in the original requirement spec. To go two levels under the main folder, you'd need to use listfolder() to return names of folders on the 2nd level. Then cycle though them in the same fashion. Be careful though as you'll have quite a few nested loops.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: how to suck out folder contents recursively

Post by PeterH »

zer0 wrote:
Huidong wrote:I mean, it works for one level under the main folder (say "subfolder"), but does not work for two levels under the main folder (I called it "sub-subfolder").
Now you're piling on additional permutations of complexity that weren't there in the original requirement spec. To go two levels under the main folder, you'd need to use listfolder() to return names of folders on the 2nd level. Then cycle though them in the same fashion. Be careful though as you'll have quite a few nested loops.
As I read in the very first post:
Huidong wrote:... do the job recursively, i.e. extracts all contents of all subfolders ...

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: how to suck out folder contents recursively

Post by zer0 »

PeterH wrote:As I read in the very first post:
Huidong wrote:... do the job recursively, i.e. extracts all contents of all subfolders ...
Fair enough, I gave pointers on how to do that in my previous post. The mechanism is the same.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

Thanks zer0, that's better than feeding me whatever I want, from which I wouldn't use the brain as much. Best regards.

admin
Site Admin
Posts: 66249
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: how to suck out folder contents recursively

Post by admin »

For reference, a working suction script is found here:
http://www.xyplorer.com/xyfc/viewtopic. ... 811#p59806

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: how to suck out folder contents recursively

Post by Huidong »

You are feeding me whatever I want, Don!

Post Reply