script to copy sevaral folder contents into one folder

Discuss and share scripts and script files...
kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

script to copy sevaral folder contents into one folder

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

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

F1 for help, advanced topics, scripting commands reference.

Command: moveto

--
highend
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: script to copy sevaral folder contents into one folder

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

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Then use a foreach loop with folderreport() and delete commands.
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: script to copy sevaral folder contents into one folder

Post 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?)


.

.

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

@Stefan

No time as well but,

Code: Select all

delete 1, 1, $fld,
won't work, you've used $FLD before :)
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: script to copy sevaral folder contents into one folder

Post by Stefan »

Right, the Shift-Key was still looked from typing the $ and sHIFT_kEY WAS PRESSED TOO THE SAME TIME :roll:

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: script to copy sevaral folder contents into one folder

Post by Stefan »

highend wrote:

Code: Select all

delete 1, 1, $fld,
won't work, you've used $FLD before :)
No, i decide to say this is an security option :lol:


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

.

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: script to copy sevaral folder contents into one folder

Post 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.
Last edited by kotlmg on 05 Nov 2011 03:16, edited 3 times in total.

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Scripting Commands Reference: goto
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

don't know where to add goto code. if i write
goto $destination will it be o.k.

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

goto $destination will it be o.k.

Code: Select all

goto $destination;
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: script to copy sevaral folder contents into one folder

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

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

Re: script to copy sevaral folder contents into one folder

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

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

some times the following error is coming.
Attachments
Clipboard01.jpg
Clipboard01.jpg (38.05 KiB) Viewed 4769 times

Post Reply