Page 1 of 1

copy files from folder to where the batch file is located

Posted: 02 Dec 2020 13:03
by rasil
hi,
I want to move files from a folder to where the batch file is located. I cannot simply just do

Code: Select all

move c:\WINSCP\*.* c:\?????
because the destination folder could be named anything or be anywhere when its in a different machine. e.g. desktop

Re: copy files from folder to where the batch file is located

Posted: 02 Dec 2020 13:27
by rasil
just a follow up I was able to do this with this script

Code: Select all

SET src_folder=WINSCP
SET tar_folder=%cd%
for /f %%a IN ('dir "%src_folder%" /b') do move "%src_folder%\%%a" "%tar_folder%\"

Re: copy files from folder to where the batch file is located

Posted: 02 Dec 2020 14:21
by aGerman
%cd% expands to the current working directory (without trailing backslash).
%~dp0 expands to the path of the script file (with trailing backslash).

Steffen