Search code examples
batch-filedoscddosboxturbo-c

Current directory in DOSBox [Optional: Using TURBO C]


I want to run a command in a specific directory and then return back. (There is a reason for it [validity of parameters...]).

I tried doing it in batch file for DOSBox...

@echo off
cd>cd.cd
cd %mypath%
dosomething 1 2 3
::I am not sure....
cd (type cd.cd) 

%CD%, %dI, FOR loop nothing works in DOSBox...

I wrote a C program but couldn't find a function that returns the current directory for TURBO C 16-bit...

Can someone please help me out with this?


Solution

  • %CD% is a variable in Windows cmd so you can't use it in MS-DOS. You can work around that by storing the current directory output from the cd command without any parameters into a variable by redirecting command output to file then read the file from disk

    • Prepare a file containing only @set cd= without any newlines. It can be created in DOS by pressing Ctrl+Z then Enter while running COPY CON. Let's name it init.txt
    • Then everytime you want to get the current directory run

      cd >cd.txt
      copy init.txt+cd.txt setcd.bat
      setcd
      
    • The last command will save the current directory into the %CD% variable

    Get current dir