System cannot find path specified

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

System cannot find path specified

#1 Post by snifferpro » 10 Dec 2017 07:46

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.
Last edited by aGerman on 10 Dec 2017 08:25, edited 1 time in total.
Reason: Code tags added

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: System cannot find path specified

#2 Post by aGerman » 10 Dec 2017 08:33

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

MicrosoftIsKillingMe
Posts: 55
Joined: 11 Dec 2017 09:08

Re: System cannot find path specified

#3 Post by MicrosoftIsKillingMe » 11 Dec 2017 10:32

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.

Post Reply