Delete Folder without deleting data files inside

Discuss and share scripts and script files...
Post Reply
flourgrader
Posts: 11
Joined: 30 Dec 2014 15:35

Delete Folder without deleting data files inside

Post by flourgrader »

Hiya Guys,
I could do with a bit of help please ?

I have a main Parent Folder which has 4000 folders inside it.
Each folder has has a different name.
I wish to keep this folder and it's name.
Inside these folders is a folder with an identical name in all 4000 folders.
I want to delete this folder but not the Data which is inside all 4000 folders .
I want that data to go into it's parent folder!

EG: Main Folder > Folder Name > Folder ID > Files

I want the Files to go into "Folder Name" and deleting "Folder ID".

This all has to be done in a batch process.
As you can see to do it one at a time it would take forever !
Any chance I can do this with XYplorer 14.30 ?

Thanks,
George.

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Delete Folder without deleting data files inside

Post by SammaySarkar »

flourgrader wrote: EG: Main Folder > Folder Name > Folder ID > Files

I want the Files to go into "Folder Name" and deleting "Folder ID".
What if some files with same name as some of "Files" already exist in "Folder Name"?
ask every time or auto-Overwrite or add suffix to moved "File" or move conflicting "File" to another subfolder?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Germany, EU

Re: Delete Folder without deleting data files inside

Post by Stefan »

Me think flourgrader means something like this:


FROM:
Main Folder > Folder Name 0001 > Folder ID > Files
...
Main Folder > Folder Name 4000 > Folder ID > Files



TO:
Main Folder > Folder Name 0001 > Files
...
Main Folder > Folder Name 4000 > Files



DO:
For each folder "Folder Name <digits>"
--- go into sub folder "Folder ID"
--- move all files up one level
--- go up one level
--- delete folder "Folder ID"
--- go up one level to "Main Folder"
Next


Right?

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Delete Folder without deleting data files inside

Post by SammaySarkar »

flourgrader wrote:Inside these folders is a folder with an identical name in all 4000 folders.
I think more like:
FROM:
Main Folder > Folder Name 0001 > Folder Name 0001 > Files
...
Main Folder > Folder Name 4000 > Folder Name 4000 > Files

TO:
Main Folder > Folder Name 0001 > Files
...
Main Folder > Folder Name 4000 > Files.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Germany, EU

Re: Delete Folder without deleting data files inside

Post by Stefan »

And I thought the sub folders of the "Folder Name <digits>" folders have always the same identical name :ninja:


So flourgrader should clarify :whistle:



 

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Delete Folder without deleting data files inside

Post by SammaySarkar »

Meanwhile, here's a little script as I interpreted the wish.
SammaySarkar wrote: I think more like:
FROM:
Main Folder > Folder Name 0001 > Folder Name 0001 > Files
...
Main Folder > Folder Name 4000 > Folder Name 4000 > Files

TO:
Main Folder > Folder Name 0001 > Files
...
Main Folder > Folder Name 4000 > Files.


As always, you should test it with with a small replaceable subset of folders before mass execution.

running: copy the code below. Open Main Menu->Scripting->Run Script... . Paste the code there click OK (or CTRL+ENTER)

Usage: point it to the "PARENT FOLDER" or "MAIN FOLDER" that you spoke of.And decide whether to move or copy. And then file movements will begin.
You will get a handful of prompts in case of file conflicts.

Code: Select all

	setting "useCustomCopy", 1; setting "backgroundFileOps", 1; setting "backgroundedFileOps", 31; //effective during this script only
	//step;
	$parent = inputfolder("<xydata>\test", "Choose the MAIN PARENT folder:");
	$subs   = listfolder("$parent",, 2+4 /*NoFiles+NoPath*/); //sep = |
	end ($subs == ''), "no subfolders!";

	foreach($sub, $subs, "|") {
		//look for same named subfolder-in-subfolder
		if  (exists("$parent\$sub\$sub") != 2)     { continue; }
		else                                       {
			$itms = listfolder("$parent\$sub\$sub",, /*4 NoPaths*/); //sep = |
			moveto "$parent\$sub", "$itms",, 2;
		}
		if (listfolder("$parent\$sub\$sub") == '') { delete 0,0, "$parent\$sub\$sub"; }
	}
	echo "finished";
[edit:it's not required to choose between copy or move]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

flourgrader
Posts: 11
Joined: 30 Dec 2014 15:35

Re: Delete Folder without deleting data files inside

Post by flourgrader »

Thanks SammaySarkar for the Script.
I tried the code out, it did not delete any of the Folder Tree Structure.
It did not ask if I wanted to Move or Copy. It asked me to point it at which Folder I wanted it to work on.
When I picked the Drive and Folder and clicked OK . It said finished.
But thanks again for spending the time on coding!

For those that are not clear in what I am after doing I will lay my Folder Tree structure out.

E:\FILMS\TITLE OF MY FILM_1\VIDEO_TS\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_2\VIDEO_TS\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_3\VIDEO_TS\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_4000\VIDEO_TS\FILES.VOBs

Where "TITLE OF MY FILM" This obviously is a unique name as it's the title of the film inside the folder!

I want the "FILES.VOBs" to be moved to the folder "TITLE OF FILM_1" then deleting "VIDEO_TS"
I want this process recurring 4000 to go through my entire film collection.

So my Folder Tree Structure Should Look like this:

E:\FILMS\TITLE OF MY FILM_1\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_2\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_3\FILES.VOBs
E:\FILMS\TITLE OF MY FILM_4000\FILES.VOBs

Thanks Again For Your Help....

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Delete Folder without deleting data files inside

Post by SammaySarkar »

well, my interpretation was obviously wrong. (you could've pointed that out earlier, though :x )

Anyways, try this script. It's basically the same script posted above, I just tweaked the relevant bits.
Usage same as before. Point it to E:\FILMS.

Code: Select all

	setting "useCustomCopy", 1; setting "backgroundFileOps", 1; setting "backgroundedFileOps", 31; //effective during this script only

	$parent = inputfolder("E:\FILMS", "Choose the MAIN PARENT folder:");
	$subs   = listfolder("$parent",, 2+4 /*NoFiles+NoPath*/); //sep = |
	end ($subs == ''), "no subfolders!";

	foreach ($sub, $subs, "|") {
		//look for same named subfolder-in-subfolder
		if (exists("$parent\$sub\VIDEO_TS") != 2) {
			continue;
		} else  {
			$itms = listfolder("$parent\$sub\VIDEO_TS",, /*4 NoPaths*/); //sep = |
			moveto "$parent\$sub", "$itms",, 2;
		}
		if (listfolder("$parent\$sub\VIDEO_TS") == '') {
			delete 0,0, "$parent\$sub\VIDEO_TS";
		}
	}
	echo "finished moving.";
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

flourgrader
Posts: 11
Joined: 30 Dec 2014 15:35

Re: Delete Folder without deleting data files inside

Post by flourgrader »

Thanks very Much SammaySarka.
It works very well on my Test Sample.
I will execute it on my film collection now !
Have yourself a Good Day !

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Delete Folder without deleting data files inside

Post by SammaySarkar »

Righto. Have yourself a great new year!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply