script to copy sevaral folder contents into one folder

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Is it reproducable (same file, produces the same error)?

I can't see anything wrong inside the script.
One of my scripts helped you out? Please donate via Paypal

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

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

error is repeating in other systems also. i have checked in win7 32 bit and win 7 64 bit systems, but the error is popping up again.
case : i have created one folder called test. within test folder i have file ClavierHelp.html.pdf
and folder ClavierHelp.html - Copy (2). folder ClavierHelp.html - Copy (2) has ClavierHelp.html - Copy (2).pdf file. when i have used your code on test folder, the following errors popped up.
Attachments
Clipboard02.jpg
Clipboard02.jpg (103.64 KiB) Viewed 3492 times
Clipboard01.jpg
Clipboard01.jpg (51.75 KiB) Viewed 3492 times

highend
Posts: 13327
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";
*/
	setting('BackgroundFileOps', 0);

	$destination = inputfolder( ,select destination folder to move to);
	$FolderList = get("SelectedItemsPathNames", "|");

	foreach($FLD, $FolderList)
	{
		if (exists($FLD)==2)
		{
			$content = folderreport("files", "r", $FLD, "r", , "|");
			foreach($Item, $content)
			{
				moveto $destination, $Item;
			}
		} else {
			moveto $destination, $FLD;
		}
		delete 1, 0, $FLD;
	}
One of my scripts helped you out? Please donate via Paypal

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

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

wonderful sir, the code is perfectly working as i desired. you are really a genius.

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

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

i have modified the above code to type the destination folder as follows. it is working. now can i have the two options ie. either browse or type the path in this code.



/* 05.11.2011, Move files and contents of folders to a different (new) folder
::load "<xyscripts>\.snippets\MoveToNewDestination.xys";
*/

setting('BackgroundFileOps', 0);
$destination = input("Enter target path");
$FolderList = get("SelectedItemsPathNames", "|");

foreach($FLD, $FolderList)
{
if (exists($FLD)==2)
{
$content = folderreport("files", "r", $FLD, "r", , "|");
foreach($Item, $content)
{
moveto $destination, $Item;
}
} else {
moveto $destination, $FLD;
}
delete 1, 0, $FLD;
}

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

Re: script to copy sevaral folder contents into one folder

Post by zer0 »

Can you please use code tags and indent as appropriate? Makes code easier to read and understand.
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

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

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

i have added two options. 1. Browse for folder, 2. Type Path. With the help of stefan sir's code i could modify the above code as follows.


Code: Select all

/* 18.11.2011, Move files and contents of folders to a different (new) folder
   ::load "<xyscripts>\.snippets\MoveToNewDestination.xys";



*/

	$Methode = inputselect(Choose methode for Moving files:, "Browse|Type Path", , 2);

	if ($Methode=="Type Path"){
              setting('BackgroundFileOps', 0); 
	$destination = input("Enter target path");
   $FolderList = get("SelectedItemsPathNames", "|");

   foreach($FLD, $FolderList)
   {
      if (exists($FLD)==2)
      {
         $content = folderreport("files", "r", $FLD, "r", , "|");
         foreach($Item, $content)
         {
            moveto $destination, $Item;
         }
      } else {
         moveto $destination, $FLD;
      }
      delete 1, 0, $FLD;
   }
                                 }

       else{
              setting('BackgroundFileOps', 0); 
	$destination = inputfolder( ,select destination folder to move to);

   $FolderList = get("SelectedItemsPathNames", "|");

   foreach($FLD, $FolderList)
   {
      if (exists($FLD)==2)
      {
         $content = folderreport("files", "r", $FLD, "r", , "|");
         foreach($Item, $content)
         {
            moveto $destination, $Item;
         }
      } else {
         moveto $destination, $FLD;
      }
      delete 1, 0, $FLD;
   }
                                }
the above code i am using regularly. it has made my day.

Zardoz2293
Posts: 577
Joined: 09 Nov 2011 20:20
Location: USA

Re: script to copy sevaral folder contents into one folder

Post by Zardoz2293 »

kotlmg wrote:i have added two options. 1. Browse for folder, 2. Type Path. With the help of stefan sir's code i could modify the above code as follows.

Code: Select all

/* 18.11.2011, Move files and contents of folders to a different (new) folder
   ::load "<xyscripts>\.snippets\MoveToNewDestination.xys";
*/
...
Kotlmg, consider using the revised code below:

Code: Select all

/* 18.11.2011, Move files and contents of folders to a different (new) folder
::load "<xyscripts>\.snippets\MoveToNewDestination.xys";
*/

$Methode = inputselect(Choose methode for Moving files:, "Browse|Type Path", , 2);

if ($Methode=="Type Path"){
	$destination = input("Enter target path");
} else {
	$destination = inputfolder( ,select destination folder to move to);
}
setting('BackgroundFileOps', 0);
$FolderList  = get("SelectedItemsPathNames", "|");

foreach($FLD, $FolderList)
{
	if (exists($FLD)==2)
	{
		$content = folderreport("files", "r", $FLD, "r", , "|");
		foreach($Item, $content)
		{
			moveto $destination, $Item;
		}
	} else {
		moveto $destination, $FLD;
	}
	delete 1, 0, $FLD;
}
Computer/Systems Background = Expert | Windows 10 Pro (64-Bit) | Dell Precision 7720

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

Re: script to copy sevaral folder contents into one folder

Post by kotlmg »

thanks Zardoz2293. your code is perfectly working.

Steel
Posts: 56
Joined: 30 Dec 2011 15:37

Re: script to copy sevaral folder contents into one folder

Post by Steel »

Hello,

I would like to use this script but I don't want it to delete anything but just to move content: is it possible?

Thank you.

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Delete the delete... line?!?

Code: Select all

delete 1, 0, $FLD;
One of my scripts helped you out? Please donate via Paypal

Steel
Posts: 56
Joined: 30 Dec 2011 15:37

Re: script to copy sevaral folder contents into one folder

Post by Steel »

highend wrote:Delete the delete... line?!?

Code: Select all

delete 1, 0, $FLD;
If I knew what to do or understood coding I wouldn't be asking in the first place. ;)

What about those } at the end?
Do they remain so that it looks like this?


} else {
moveto $destination, $FLD;
}
delete 1, 0, $FLD;
}

Thank you

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Do they remain?
Yeah.
One of my scripts helped you out? Please donate via Paypal

Steel
Posts: 56
Joined: 30 Dec 2011 15:37

Re: script to copy sevaral folder contents into one folder

Post by Steel »

highend wrote:
Do they remain?
Yeah.
Thanks but proving I am no expert I cannot seem to make it work.

I placed a button on the Toolbar and in "On Click" I placed the code minus the delete 1, 0, $FLD;

When I click on the button I get a dropdown with some of the code: what am I doing wrong?

Thank you

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

Re: script to copy sevaral folder contents into one folder

Post by highend »

Probably because you have copied one of the later postings that showed the code in code tags.

Each line of the code must be preceeded with at least a space (or in my case: a tab) as a general rule
(excluding the first line, comments or subcode).

The last two code postings don't obey this rule and you have to reindent it yourself.
One of my scripts helped you out? Please donate via Paypal

Post Reply