xcopy file and folder from a changing directory

I have been having 0 files copied message when attempting to Xcopy files. Note that I managed to do it successfully by specifying an exact source path as shown below:

xcopy /y %USERPROFILE%\Desktop\WinXTweak\program1.exe %WINDIR%\
xcopy /y %USERPROFILE%\Desktop\WinXTweak\program2.exe %WINDIR%\
xcopy /y %USERPROFILE%\Desktop\WinXTweak\program3.exe %WINDIR%\

Of course, this would only work if the WinXTweak folder is on the desktop. I would like to be able to copy it into a USB drive for instance or any location in my PC and run it. The location of the batch file is inside the WinXTweak folder too. I could not figure out what to do. I tried the ones below but it did fail.

xcopy /y program1.exe %WINDIR%\
xcopy /y program2.exe %WINDIR%\
xcopy /y program3.exe %WINDIR%\

Thanks all in advance,

1 answer

  • answered 2020-05-30 21:51 Juan Miguel De Guzman

    Thanks all for your reply. After reading more stuff online, I was able to resolve the issue by using the following code. I am a newbie at this, and there might be a much simpler way this is what I used.

    @echo off
    set source=%~dp0*.exe
    set target="%WINDIR%"
    xcopy /y "%source%" "%target%"

    The suggested answers I will take note and learn so I can use it in the future.

    Thank you for helping and best regards,