How do I move every file in a tree to the root of the tree?
My original post neglected to include the file's extension in the move command.
%~ni
only returns the basename, you need to use%~nxi
to get both the filename and extension! I hope you haven't mangled your filenames on my account!(
From a Command Prompt:
cd /d C:\Path\To\A
for /r %i in (*) do @move "%i" "%~nxi"
If you need to cleanup the empty folders afterward:
for /d %i in (*) do @rd /s /q "%i"
Now, if you have any filename clashes, you're on your own. You can add the /y
parameter to the move
command (before the "%i"
) to force overwrites. If you want something different, you'll need another program that can auto-rename everything for you.
Also, if you want to use this in a batch file, change all the %
to %%
.
Create a folder and copy all the other folders into it, then right click that folder and select Search. In the search box enter *.*
.
This will list all the files and folders. Select all the files you want in your root directory and cut them. Navigate to your root directory and paste all the files there.