Page 1 of 1

System cannot find path specified

Posted: 10 Dec 2017 07:46
by snifferpro
I'm trying to use the following batch file to copy a file
from
C:\Users\DickSL\AppDAta\Roaming\Testbat\Testbati.txt
to
F:\Testbat\%filename%

Batch file

Code: Select all

@echo off
set "hr=%time:~0,2%-%time:~3,2%-%time:~6%"
echo %hr%
set "filename=%date%_%hr%_Testbati.txt" 
echo %filename%
pause
copy c:\users\DickSL\AppData\Roaming\Testbat\testbati.txt f:\Testbat\"%filename%"
pause
When I run the bat I get
"The system cannot find the path specified"

Testbati.txt is definitely in the directory specified in the copy command above.

The echo statement below the set command %filename% echoes the following
Sun 12/10/2017_ 6-02-41.94_Testbati.txt correctly.

Why am I getting the path not found?

Thanks in advance.

Re: System cannot find path specified

Posted: 10 Dec 2017 08:33
by aGerman
Slashes (/) are not allowed in file names and that's why you have to replace them (e.g. using %date:/=_%).

Try

Code: Select all

@echo off
set "hr=%time:~0,2%-%time:~3,2%-%time:~6%"
echo %hr%
set "filename=%date:/=_%_%hr%_Testbati.txt" 
echo %filename%
pause
if not exist "f:\Testbat\" md "f:\Testbat"
copy "%APPDATA%\Testbat\testbati.txt" "f:\Testbat\%filename%"
pause
Steffen

Re: System cannot find path specified

Posted: 11 Dec 2017 10:32
by MicrosoftIsKillingMe
That message could refer to either the source or destination being invalid. Are you certain it's the source? Maybe
copy "%APPDATA%\Testbat\testbati.txt" c:\GoodDir
to assure that, where GoodDir is a directory that you are permitted to copy to.

I suggest this because I would bet that the destination is the culprit.