Page 1 of 3
script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 04:51
by kotlmg
i need a script to copy all the contents of selected folders into one folder of user choice. after copying original selected folders to be deleted. i don't know whether this script is already available or not.
thanks in advance.
Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 08:32
by highend
F1 for help, advanced topics, scripting commands reference.
Command: moveto
--
highend
Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 09:53
by kotlmg
move to command is moving all the selected folders. but i want only the contents in folders to be moved to new location and selected folders to be deleted. there should be an option to add all the folders contents to copied. folders may be in separate paths. basic requirement is that whenever we download files from torrents, they are downloaded in separte folders. i want all those contents of different to be moved to one folder and selected folders to be deleted. entire process should work with script.
Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 10:24
by highend
Then use a foreach loop with folderreport() and delete commands.
Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 10:36
by Stefan
I wanted to provide an script the whole morning, but have no time
and then i got an BSOD two times with this wrong written script (separator CRLF <> | ):
Code: Select all
//inputfolder([path], [caption])
$destination = inputfolder( ,select dest folder);
$FolderList = get("SelectedItemsPathNames"); //[separator=CRLF],
foreach($FLD, $FolderList) //[separator=|]
{
if (exists($FLD)==2)
{
//folderreport([type=dump], [target=clipboard], [folder], [flags], [outputfile], [separator])
$content = folderreport("files","r", $FLD, "r");
//moveto location, [source], [rootpath], [flags]
moveto $destination, $content;
//delete [recycle=1], [confirm], [itemlist]
delete 1, 1, $fld,
}
}
Perhaps there are more errors in (e.g. $Content needs the right delimiter for moveto?), and there is no error handling at all!
If i find some more time i will update an working script. Or someone else will do....? (wasn't there an Prune script doing something like this already?)
.
.
Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 10:55
by highend
@Stefan
No time as well but,
won't work, you've used $FLD before

Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 11:24
by Stefan
Right, the Shift-Key was still looked from typing the $ and sHIFT_kEY WAS PRESSED TOO THE SAME TIME

Re: script to copy sevaral folder contents into one folder
Posted: 04 Nov 2011 20:26
by Stefan
highend wrote:
won't work, you've used $FLD before

No, i decide to say this is an security option
Here is an working script, at least it works for some simple tests. It even move the sub-folders.
But please take care and test yourself before use it for real. I myself didn't enjoy the testing much this days.
F.ex. I don't know what happens if an item could not be moved and you delete the folder automatically at the end?
Code: Select all
//// Where to move to?:
////inputfolder([path], [caption])
$destination = inputfolder( ,select destination folder to move to);
//// Get the list of selected items:
$FolderList = get("SelectedItemsPathNames", "|");
//// For each selected item DO:
foreach($FLD, $FolderList)
{
//// If exists() returns '2' it is detected as folder
if (exists($FLD)==2)
{
//// Get an list of all files and folder recursive from each selected folder:
////folderreport([type=dump], [target=clipboard], [folder], [flags], [outputfile], [separator])
$content = folderreport("items","r", $FLD, "r",,"|");
////debug test:
//text replace($content, "|", "<crlf>");
//// Use moveto() to move the collected items to destination:
////moveto location, [source], [rootpath], [flags]
moveto $destination, $content;
//// Delete the selected folders:
////delete [recycle=1], [confirm], [itemlist]
delete 1, 1, $fld; //// use upper case $FLD to enable this feature!
}
}
Only problem is, script says always that the destination folder does not exists?
Code: Select all
---------------------------
Verschieben
---------------------------
Der Ordner < my destination folder here> ist nicht vorhanden.
Möchten Sie ihn erstellen?
---------------------------
Ja Nein
---------------------------
That "prune" which i had in mind can be found there >
http://www.xyplorer.com/xyfc/viewtopic. ... 26&p=44915
.
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 03:03
by kotlmg
//// Where to move to?:
////inputfolder([path], [caption])
$destination = inputfolder( ,select destination folder to move to);
//// Get the list of selected items:
$FolderList = get("SelectedItemsPathNames", "|");
//// For each selected item DO:
foreach($FLD, $FolderList)
{
//// If exists() returns '2' it is detected as folder
if (exists($FLD)==2)
{
//// Get an list of all files and folder recursive from each selected folder:
////folderreport([type=dump], [target=clipboard], [folder], [flags], [outputfile], [separator])
$content = folderreport("items","r", $FLD, "r",,"|");
////debug test:
//text replace($content, "|", "<crlf>");
//// Use moveto() to move the collected items to destination:
////moveto location, [source], [rootpath], [flags]
moveto $destination, $content;
//// Delete the selected folders:
////delete [recycle=1], [confirm], [itemlist]
delete 1, 1, $FLD ; //// use upper case $FLD to enable this feature!
}
}
thank you very much. the above code is working for me. one problem with above code is if different folders are having the same file/folder name, then they are getting overwritten. instead if they are moved as files /folders serial numbered i.e. file1, file1_1, file1_2 or folder1, folder1_1, folder1_2 etc, it will be good.
is it possible to open the destination folder in xyplorer once the above job is finished? thanks a lot in advance.
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 03:07
by highend
Scripting Commands Reference: goto
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 03:36
by kotlmg
don't know where to add goto code. if i write
goto $destination will it be o.k.
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 04:00
by highend
goto $destination will it be o.k.
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 05:24
by kotlmg
thanks a lot. the script is perfectly working. at present the script is able to move only folders when both files and folders are selected from the current path . it is not moving the files. sometimes cannot find the files message is appearing. is it possible to select files or folders from different paths by modifying the above code?
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 11:21
by highend
Code: Select all
/* 05.11.2011, Move files and contents of folders to a different (new) folder
::load "<xyscripts>\.snippets\MoveToNewDestination.xys";
*/
$destination = inputfolder( ,select destination folder to move to);
$FolderList = get("SelectedItemsPathNames", "|");
foreach($FLD, $FolderList)
{
if (exists($FLD)==2)
{
$content = folderreport("items","r", $FLD, "r",,"|");
foreach($Item, $content)
{
moveto $destination, $Item;
}
delete 1, 0, $FLD;
} else {
moveto $destination, $FLD;
}
}
Re: script to copy sevaral folder contents into one folder
Posted: 05 Nov 2011 12:22
by kotlmg
some times the following error is coming.