John
John

Reputation: 21

Move a file using bat from folder

I'm trying to move a file from the folder the batch file is in to a folder on the C:\ drive, and I just can't figure out how.

I tried using dir to get the parent folder, but it registered an error.

What would I use?

move dir\test.bat C:\Some folder

Upvotes: 2

Views: 15131

Answers (4)

NiematojakTomasz
NiematojakTomasz

Reputation: 2473

You must use backslashes \ as path separators. According to your comment you used forward slash / in source path.

Upvotes: 0

Andriy M
Andriy M

Reputation: 77677

To reference a file or a folder relative to the location of the batch script you need to use the %0 parameter and the ~dp combined modifier. The following moves the file somefile.txt to Some folder on C::

MOVE "%~dp0somefile.txt" "C:\Some folder"

Upvotes: 0

John Cornell
John Cornell

Reputation: 1087

This may be a permissions issue for the path you're trying. Try opening the command line as an administrator (right click -> run as administrator)

This works fine for me when the batch file is run from the directory that the test file is in:

move "test.txt" "C:\Test"

Upvotes: 1

fedxc
fedxc

Reputation: 195

I think you are missing the "":

move "A:\test.bat" "C:\Some folder"

Upvotes: 2

Related Questions