CMD: Bat to Exe Converter - Temp directory problem

16,127

Without having Bat to Exe changed by the author, I think you have two options:

  1. Remove the need for accessing %~dp0

    Perhaps you can merge file.txt with the include option of Bat to Exe into the EXE file. If so, "file.txt" will automatically be unpacked in the current directory when running your compiled exe, and you can it access by %CD%\file.txt.

  2. Get %~dp0 from outside and pass it to the exe as a command line parameter.

    This can be done by a simple starter bat file that resides in the same directory as your compiled main batch file. This script schould contain the line

    YourCompiled.Exe %~dp0% %%* 
    

    Your compiled exe then gets its directory from %1. So you cannot pack everything into one exe, but the main portion of it, perhaps that is sufficient for you.

Share:
16,127
Deniz Zoeteman
Author by

Deniz Zoeteman

Back-end (web)development. Specialised mostly in PHP.

Updated on June 18, 2022

Comments

  • Deniz Zoeteman
    Deniz Zoeteman almost 2 years

    i am using 'Bat to Exe Converter' to convert my batch files to exe format.

    Now, i am running into some problems. Whenever i convert something, and i set 'Working Directory' to 'Current Directory', and i start my exe in echo on mode, this is what i end up with to check if there is a specific file in the directory of my exe:

    the actual command: if not exist "%~dp0\file.txt" goto :nofile

    output: if not exist "C:\Users\MyUser\AppData\Local\Temp\4CBC\\file.txt" goto :nofile

    Can anyone help me with this? I don't want it in the temp directory, i want it to be in the directory of my exe.

    Thanks.