user2077474
user2077474

Reputation: 353

Batch file to move files to another directory

I hope that you can help me with this one. It might have been asked multiple times already (I know that), but for some reason, I just can't have it working.

I want to move some files from the "files" directory to the root directory.

So the files are, for example:

test1.txt test2.txt test3.zip test4.zip test5.exe test6.exe

I want these files to be moved to different directories.

So I'm using something like this:

move files\*.txt ..\txt /q
move files\*.zip ..\zip /q
move files\*.exe ..\exe /q

But I always get errors. It can't find the files and then the CMD stops working.

Thanks.

EDIT:

It's working like this:

move /y .\files\*.txt ..\txt
move /y .\files\*.zip ..\zip
move /y .\files\*.exe ..\exe

But now it won't move the file to the parent directory.

Upvotes: 24

Views: 160383

Answers (3)

lorfo
lorfo

Reputation: 11

Try:

move "C:\files\*.txt" "C:\txt"

Upvotes: 1

yu yang Jian
yu yang Jian

Reputation: 7181

Suppose there's a file test.txt in Root Folder, and want to move it to \TxtFolder,

You can try

move %~dp0\test.txt %~dp0\TxtFolder

.

reference answer: relative path in BAT script

Upvotes: 3

Jerry
Jerry

Reputation: 4408

/q isn't a valid parameter. /y: Suppresses prompting to confirm overwriting

Also ..\txt means directory txt under the parent directory, not the root directory. The root directory would be: \ And please mention the error you get

Try:

move files\*.txt \ 

Edit: Try:

move \files\*.txt \ 

Edit 2:

move C:\files\*.txt C:\txt

Upvotes: 21

Related Questions