Page 1 of 2
how to suck out folder contents recursively
Posted: 20 May 2011 23:08
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?
Re: how to suck out folder contents recursively
Posted: 21 May 2011 00:26
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
}
Re: how to suck out folder contents recursively
Posted: 21 May 2011 00:50
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 00:58
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 01:53
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\*";
}
Re: how to suck out folder contents recursively
Posted: 21 May 2011 02:14
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 02:27
by Huidong
Hi zer0, one question, it appears to me that $name is not used, why's that?
Re: how to suck out folder contents recursively
Posted: 21 May 2011 02:33
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 02:36
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").
Re: how to suck out folder contents recursively
Posted: 21 May 2011 12:53
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 18:14
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 ...
Re: how to suck out folder contents recursively
Posted: 21 May 2011 21:34
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.
Re: how to suck out folder contents recursively
Posted: 21 May 2011 21:39
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.
Re: how to suck out folder contents recursively
Posted: 22 May 2011 19:17
by admin
For reference, a working suction script is found here:
http://www.xyplorer.com/xyfc/viewtopic. ... 811#p59806
Re: how to suck out folder contents recursively
Posted: 22 May 2011 19:22
by Huidong
You are feeding me whatever I want, Don!