Search code examples
batch-filecmdxcopy

Copying file into unknown directory in WinBatch


I am writing my own Half-Frontend Console App. I have a problem with the XCOPY command. I want to copy PBOOT.PBP file into folder

ux0_pspemu_temp_game_PSP_GAME_!randomletters&numbers!

Example:

xcopy %CD%\data\easyinstaller\ARK\PBOOT.PBP %CD%\Delete_me\ux0_pspemu_temp_game_PSP_GAME_!randomletters&numbers!

In this case the folder name is: ux0_pspemu_temp_game_PSP_GAME_NPEG00024

But in other cases the name will differ - e.g. ux0_pspemu_temp_game_PSP_GAME_NPUH99313.


Solution

  • You could probably just determine the name of the directory first, possibly setting it as a variable for easy re-use:

    SET "DESTDIR="
    FOR /D %%A IN ("%CD%\Delete_me\ux0_pspemu_temp_game_PSP_GAME_NP*") DO SET "DESTDIR=%%A"
    IF NOT DEFINED DESTDIR EXIT/B
    COPY /Y "%CD%\data\easyinstaller\ARK\PBOOT.PBP" "%DESTDIR%"