The linked question may assist in context of my query: Get filename in batch for loop
I'm just not catching on to the rules of substitution, but I think this is a question with a similar answer...
I'm attempting the same sort of move action using the following batch sequence. Anyone able to help me correct the syntax?
@echo off
set source=C:\Users\my name\some long path with spaces
set target=C:\Users\my name\a different long path with spaces
for %%F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%F" "%target%\%~nF.jpg"
The idea is to copy all files with no extension where destination with matching filename exists with specific extension into the destination with correct extension. Thanks in advance is anyone is able to assist!
Edit: Thanks for the references Daniel, but I'm not trying to copy a filename to destination with matching extension. I'm trying to copy filename to same filename with new extension
Example:
source\filename001
destination\filename001.jpg
- do nothing
source\filename002
destination\{no match}
- copy source\filename002 to destination\filename002.jpg
Alex, I'm not sure what to do from there. I looked at the output when running without echo off, and that's why I'm posting this question. I don't understand how to modify the substitutions to work correctly.
Output errors from batch:
for %%~F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%F" "%target%\%~nF.jpg"
The following usage of the path operator in batch-parameter substitution is invalid: %~nF.jpg" copy "%%F" "%target%\%~nF.jpg"
for %%F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%~F" "%target%\%~nF.jpg"
The following usage of the path operator in batch-parameter substitution is invalid: %~nF.jpg" copy "%%~F" "%target%\%~nF.jpg"
SOLUTION: Thanks for the assist/solution/guidance!
set "source=C:\Users\my name\some long path with spaces"
set "target=C:\Users\my name\a different long path with spaces"
for /F "delims=" %%F in (
'Dir /B "%source%\*." '
) do if not exist "%target%\%%~nF.jpg" copy "%source%\%%~F" "%target%\%%~nF.jpg"