The main mistake is on command line:
move "%filesource%\%filename%" %filedestination
The second %
is missing on referencing environment variable filedestination
.
The destination path should be also enclosed in double quotes in case of containing a space or one of these characters &()[]{}^=;!'+,`~<|>
.
And it should be made sure that destination path really ends with a backslash to move the file into this directory because of otherwise it would be possible to move the file to a directory with a different file name.
So this command line should be:
move "%filesource%\%filename%" "%filedestination%\"
But honestly the batch file needs much more code to be fail safe. For example:
@echo off
goto Main
:UserPrompt
set "UserInput="
set /P "UserInput=Enter file %~2: "
rem Has the user entered no string?
if not defined UserInput goto ErrorInput
rem Remove all double quotes.
set "UserInput=%UserInput:"=%"
rem Has the user entered a string consisting only of double quotes?
if not defined UserInput goto ErrorInput
rem Check if file or directory exist at all.
if %1 == FileName (
rem The file name should not contain a directory separator.
if not "%UserInput:\=%" == "%UserInput%" goto ErrorInput
if not "%UserInput:/=%" == "%UserInput%" goto ErrorInput
if not exist "%FileSource%%UserInput%" (
echo/
echo There is no file "%FileSource%%UserInput%"
echo/
pause
echo/
goto UserPrompt
)
rem Prevent moving the batch file.
for %%I in ("%FileSource%%UserInput%") do if "%%~fI" == "%~f0" (
echo/
echo This batch file cannot be moved.
echo/
pause
echo/
goto UserPrompt
)
goto ReturnValue
)
rem Get full path in case of user entered a relative path.
for %%I in ("%UserInput%") do set "UserInput=%%~fI"
if not "%UserInput:~-1%" == "\" set "UserInput=%UserInput%\"
if not exist "%UserInput%" (
echo/
echo There is no directory "%UserInput%"
echo/
pause
echo/
goto UserPrompt
)
:ReturnValue
set "%1=%UserInput%"
goto :EOF
:ErrorInput
echo/
echo You did not enter correct information.
echo/
pause
echo/
goto UserPrompt
:Main
setlocal EnableExtensions DisableDelayedExpansion
call :UserPrompt FileSource "source path"
call :UserPrompt FileTarget "destination path"
call :UserPrompt FileName "name to look for"
set "LogFile=%TEMP%\%~n0.tmp"
echo Moving "%FileName%" from "%FileSource%" to "%FileTarget%".>"%LogFile%"
move /Y "%FileSource%%FileName%" "%FileTarget%" 2>>"%LogFile%"
echo/>>"%LogFile%"
Notepad.exe "%LogFile%"
del "%LogFile%" 2>nul
endlocal
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
del /?
echo /?
endlocal /?
for /?
goto /?
if /?
move /?
pause /?
rem /?
set /?
setlocal /?
See also: