How to remove subfolders but keep files

I have a large repertoire of epublications (or music) in folders by writer, with none or many publications in each folder. However before, tright here are a variable number of subfolders under each of these main folders, each subfolder has a even more 1-3 files (or might be empty).What I would choose to execute is: a) move all the papers in subfolders up one level to the parent folder, then delete the newly emptied SUB-folder. The last format would certainly simply be the original repertoire of folders, yet no subfolders left (and also no files deleted!).

You watching: How to remove subfolders but keep files

To make it even more complicated, tright here just could be a even more sub-sub-folder that I have missed. I obviously I do not want to shed its contents either, yet relocate those files also to the parent.. Basically I want to collapse a tree upwards, keeping the documents / killing the folders.

I wonder if anyone has actually any type of concepts on a switch I can produce for this? This difficulty commonly arises for me, and also its extremely tedious and also hard on the fingers to carry out such a repeated job manually.


I wouldn"t make a button for this, I"d sindicate put the lister in flat view then drag and drop the records approximately whichever before parent folder you wanted.


Have a look in this thread:

Moving records around via conmessage menus>

The code you´re in search of could be this one:


nofilenamequotingCopy MOVE FILE "filepath$*" HEREDelete QUIET NORECYCLE

I´d strongly advise you to check it in some test folders initially, bereason they contain a "dangerous"Delete QUIET NORECYCLE, so your empty folders will be erased.


I wouldn"t make a switch for this, I"d ssuggest put the lister in level check out then drag and also drop the papers up to whichever parent folder you wanted. Thanks for the idea John. I have been doing this procedure up till currently already and also it works fine for one small tree at a time. The problem is that tright here are numerous folders containing subfolders! I need to select each collection of documents in each subfolder manually, and also move the subdocuments up a folder level manually for each one. It functions, yet guy its difficult on my wrist and fingers after a few minutes of repetitive moutilizing. This is specifically the procedure I am attempt to automate.

The code you´re looking for might be this one:


nofilenamequotingCopy MOVE FILE "filepath$*" HEREDelete QUIET NORECYCLE I´d strongly advise you to examine it in some test folders initially, because they contain a "dangerous"Delete QUIET NORECYCLE, so your empty folders will certainly be erased. Thanks abr. I tried your command also, and it partly works on a SINGLE folder (with subfolders) at a time, but just under particular conditions/situations, and does not work-related on multiple folders at when. its fairly a mess in terms of what I would certainly prefer to achieve.I might not have actually been clear sufficient on what I need to achieve. I have to select a primary folder that consists of in it (say) 10 folders each named after (say) one author (allows call these 10 the parent folders I want to keep). Each of the 10 parent folders I have actually schosen has: a) a file or even more in them and b) a subfolder with a record or even more in that. When I select the first 10 parent folders (of authors) I would certainly favor the command also button to: a) LEAVE the existing documents in the parent folders alone and also also leave those parent author folders alone, but b) take each subfolder, and relocate the records in them up one level and then delete that empty subfolder. The outcome is that the parent folder is retained, all subfolders are gone, and also their previous contents are in the parent folder currently.

Start:folder1: file1.....subfolderA: file 2, file3folder2: (there are no files here).....subfolderB: file 4, file5etc

Result:folder1: file1, file 2, file3folder2: file 4, file5etc

What I gain through your command is all the subfolders relocated up a level, however they are still the exact same subfolder names. So, if i had 10 folders via 1 subfolder in each, the result of this button is currently as much as 20 folders. ie the contents of the subfolders are not relocated one level up, but the entire subfolder is relocated. Secondly, all the papers in the list of folders are moved up one level right into a solitary folder. If the parent folder is empty at the start (no files, however has a subfolder through files), then this command also makes the subfolder the parent and deletes the original parent (so thanks for the hazard warning).

So its not working the way I require (yet!). I additionally have to choose dozens of main folders to run it on, or else i need to run it one folder at a time (too slow). I will examine out the various other thcheck out, but some of them seem like batch documents not button.

See more: Logitech Headset One Side Not Working, Logitech Usb Headset No Sound On Left Ear


If I understand also you properly now Phil, I don"t know of a method to carry out it completely within Opus various other than drag and also drop. You have the right to go the various other way and also relocate files from a parent folder to the folder you"re in, however if there"s a way to relocate subfolder records to the folder you"re in, I"m not mindful of it.

So barring someone else via more smarts than I have actually coming up with a completely Opus solution, I"d use a batch file via an Opus button to execute this. As constantly with somepoint rather complex, test it thoabout prior to you usage it on anypoint important! It functions for me on my Windows 7 machine, and also it must work-related on various other versions of Windows, yet still, provide it a great testing on test files and folders.

Ok, that sassist, here"s the means I would certainly do this. First usage Notepad to produce a new message file and also paste the complying with right into it:


echo offsetregional enabledelayedexpansioncollection SRC=%1if "%2" neq "Opus" goto :oops1if "%~1" equ "" goto :oops2

for /r %SRC% %%a in (*) do (contact :procedure "%%a" %SRC%)exit

:processif "%~dp1" equ "%~2" goto :EOFset X=%~1relocate "%X%" "%~2"goto :EOF

:oops1echo This script should be run from Opuspauseexit

:oops2echo You need to have folders selectedpauseexit

Save that file giving it the name you desire. I named mine "D:MinecmdMove Subfolder Files to Parent Folder.cmd"

Next off in Opus, create a new button and also set it up favor the display screen shot below. Note you will have to adjust the "D:MinecmdMove Subfolder Files to Parent Folder.cmd" route in my Opus switch to the course where you put your batch file, but that must perform it.

*


You could perform it making use of a rename manuscript, but if using the batch file functions then that seems simply as good to me.


Wow John this works very well indeed. Thanks for such clear and also extremely precise instructions also. I was not certain just how you would run a cmd file from a switch till now! As it is, this manuscript functions and is exceptionally very timesaving.

..however..a) (a minor point) The freshly empty subfolders are not deleted (and also I require them to be gone). A workaround after running your manuscript is to check out the tree in View->Flatview->Mixed, sort by dimension, and also then delete all the empty folders. This is fairly simple. Can the script be modified to delete them? Or is that too risky? Its not worth the majority of trouble.

b) (a far-ranging point) There are fewer papers in my test runs after the script, than prior to. Its not a folder count, yet a paper count thats much less. On inspection I discovered that prior to running the manuscript some of the subfolders had actually consisted of a record through the very same name as one already in the parent folder (yet a different version/size) (watch folder 3 example below). Your manuscript overwrites the parent file through the subfolder file. What would be better is that as soon as such a thing happens, the file moving up a level from the subfolder is renamed once there currently exists a paper via the same name, such as appfinishing "_01", "_02" and so on to the finish of the filename (prior to the extension). If the preexisitng file is the exact same size, then it does not matter either way (overcreate OR rename the new).

Start:folder1: file1.....subfolderA: file2, file3folder2: (there are no documents here).....subfolderB: file4, file5folder3: file6.....subfolderB: file6, file7etc

Result:folder1: file1, file2, file3folder2: file 4, file5folder3: file6, file6_01, file7etc

Thanks aget, even what you have done so much is a great excellent help.


phil_ga:

a) (a minor point) The freshly empty subfolders are not deleted (and also I need them to be gone). A workapproximately after running your script is to view the tree in View->Flatview->Mixed, sort by dimension, and then delete all the empty folders. This is sensibly basic. Can the manuscript be modified to delete them? Or is that also risky? Its not worth many trouble.

a) I would do that in a 2nd unassociated procedure. Maybe set the Opus switch up so a left click relocated the files and also a appropriate click deleted the empty folders.

See more: The Sync Host_Session1 Service Terminated Unexpectedly, Microsoft Knowledge Base Archive


phil_ga:

b) (a far-reaching point) Tright here are fewer papers in my test runs after the manuscript, than prior to. Its not a folder count, yet a file count thats much less. On inspection I discovered that before running the script some of the subfolders had actually had a document with the very same name as one already in the parent folder (but a various version/size) (see folder 3 example below). Your manuscript overwrites the parent file with the subfolder file.

b) I realized that after I posted the above script. As you noticed, the MOVE procedure of it literally moves the papers and overwrites any documents in the parent folder that have actually the precise very same name. Tomorrow I"ll watch if I can not tweak the manuscript so it renames rather of overcreating (right currently I"ve acquired a cold beer and also a pizza calling my name).

*