问题
Hi everyone I need to extract multiple java files, from one directory to a root directory, but I need to preserve de first level. there are many files and many different folders, so any help is appreciated Here is an example:
What I need to do is make it so that
|ROOTDIRECTORY
| |FOLDER1
| | SUBFOLDER
| | | JA.JAVA
| |FOLDER2
| | SUBFOLDER
| | | AAAA.JAVA
| |FOLDER3
| | SUBFOLDER
| | | JAAAA.JAVA
| |FOLDER4
| | SUBFOLDER
| | | |SUBSUBFOLDER
| | | JAV.JAVA
Becomes
|ROOTDIRECTORY
| |FOLDER1
| | JA.JAVA
| |FOLDER2
| | AAAA.JAVA
| |FOLDER3
| | JAAAA.JAVA
| |FOLDER4
| | JAV.JAVA
In this example I have put 2 levels of subfolders, but there are an undetermined number of sub-levels
I think there has to be a way to do this "quickly". There are more than 500 folders and 1,000,000 files.
any idea is welcome
回答1:
I can imagine this is not exactly what you're looking for, but I have solved this kind of situations in the past, and mostly I did it in the following way (more ore less):
forfiles /S /M *.Java /C "cmd /C echo @path"
This is not moving anything, it's just showing the paths of the files, with complete directory structure.
I gives a list, containing (according to your example) like this:
C:\Folder1\Subfolder\ja.java
...
C:\Folder4\Subfolder\Subsubfolder\jav.java
Then I do two things: I keep this list somewhere, and with the copy, I turn this into the following list:
C:\Folder1\ja.java
...
C:\Folder4\jav.java
I do this by replacing "C:\Folder1\Subfolder\" by "C:\Folder1\", replacing "C:\Folder4\Subfolder\Subsubfolder\" by "C:\Folder4\", using a simple replacement command in a text editor (like Notepad++).
Then I use the column mode of that text editor to create the following kind of commands:
mv C:\Folder1\Subfolder\ja.java C:\Folder1\ja.java
....
mv C:\Folder4\Subfolder\Subsubfolder\jav.java C:\Folder4\jav.java
I can predict your reaction "Man, that's lame!", but I see two important points:
- In your situation, you want to copy not to the parent folder, but sometimes to the parent's parent folder, which makes the whole thing quite complicated.
- My solution gives you a way to completely verify if everything you're doing is correct before you actually start executing it (you can even just try out some lines and see if it works as expected).
Good luck with it
来源:https://stackoverflow.com/questions/61728200/copy-all-files-in-his-own-parent