Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 804
user2077474 Avatar asked Apr 26 '13 20:04

user2077474


People also ask

How do I move files from one folder to another in script?

You can automatically move files from one folder to another by using a script that uses Robocopy, a command-line utility which comes with Windows 10. To automated file transfer, you need to use Robocopy script, add frequency in days, source and destination folder paths.

How do I move files from one directory to another in command prompt?

Highlight the files you want to move. Press the keyboard shortcut Command + C . Move to the location you want to move the files and press Option + Command + V to move the files.


Video Answer


3 Answers

/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 
like image 57
Jerry Avatar answered Sep 25 '22 13:09

Jerry


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

like image 36
yu yang Jian Avatar answered Sep 21 '22 13:09

yu yang Jian


Try:

move "C:\files\*.txt" "C:\txt"
like image 38
lorfo Avatar answered Sep 24 '22 13:09

lorfo