1

On a Windows machine, I've got about 50 subdirectories in the same directory, each with around 5 files in it. I want to get all 250-or-so files into one directory.

In a UNIX system, I'd just open a shell, type

mv */* ./

and be done with it.

I don't know how to do this in Windows. move */* ./ doesn't work.

1
  • windows uses \ not / as a path separator, because Microsoft
    – Bravo
    Commented Sep 30, 2023 at 7:54

2 Answers 2

2

This command is to be entered in the Command Prompt when the directory in question is the current:

for /r %i in (*.*) do move "%i" .

Note that overwriting files with the same name will fail.
Note also that it will move files from any depth, so do not use this command if your folders have sub-folders.

2
  • Thanks! That ... almost worked. It worked when I put the last %i in quotes, as some of the names had spaces in them. :)
    – onigame
    Commented Sep 30, 2023 at 9:40
  • I added the quotes to my answer.
    – harrymc
    Commented Sep 30, 2023 at 10:08
0

This command can be used in batch file or CMD:

forfiles /P . /S /M * /C "cmd /c if @isdir==FALSE move @path %cd%"

References: Example of forfiles

Note that overwriting files with the same name will overwrite it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .