Reputation: 339
I'm a beginner with batch. I would like to copy file in \Debug\test.ext
into ..\..\new
by batch command.
I tried copy "\Debug\text.txt" "..\..\new"
, but get error "the system cannot find the file specified"
Upvotes: 31
Views: 92779
Reputation: 647
The proper command in Windows 10 for relative paths is:
copy "%~dp0%\your_file_name.extension" "%systemdrive%\Some Folder\Other Folder"
Explanation:
%~dp0%
set the current directory. No worry about drive letter or how many levels folders you have. It can be used for forward and backward folders as "%~dp0%\subfolder\your_file.ext"
or "%~dp0%\..\..\your_file.ext"
(>>> for backward, please consult this link Get the path two directories up in batch file )%systemdrive%
is as it name, the drive were the Windows system files are.Upvotes: 0
Reputation: 1
If you are using bat for running the copy commands, your syntax should be.
bat 'copy "C:\\Program Files (x86)\\ApplicationFiles\\firstfolder\\application.yml" "C:\\Program Files (x86)\\ApplicationFiles\\secondfolder\\application.yml"'
There are two main things in this above command:
Upvotes: 0
Reputation: 1
To properly refer to the complete path, need to include path with drives along with folder names and file name having correct file format.
for example :
"C:\Testfolder\test.txt"
if referring in network then " \\192.168.1.225\c$\testfolder\test.txt"
It will work correctly .
Upvotes: -1
Reputation: 56155
if you start your path with \
, it's an absolute, not a relative path.
Try copy "Debug\text.txt" "..\..\new"
instead
Upvotes: 48
Reputation: 57242
if you have Debug
subdir try with
md "..\..\new" >nul 2>&1
copy ".\Debug\text.txt" "..\..\new"
md
will create a new
directory two levels up if you don't have it already.
Upvotes: 1
Reputation: 1121
It means that you have not specified the correct path. Make sure you specify correct full path of the file. .
Instead of "\Debug\text...." specify the entire path like "C:\Debug\text..."
Upvotes: -1