Current directory in DOSBox [Optional: Using TURBO C]
我想在特定目录中运行命令,然后返回。 (有一个原因[参数的有效性...]。)。
我尝试在DOSBox的批处理文件中执行此操作...
我编写了一个C程序,但是找不到返回TURBO C 16位当前目录的函数...
有人可以帮我吗?
中读取文件
-
准备一个仅包含
@set cd= 且没有换行符的文件。可以在DOS中通过在运行COPY CON 的同时按Ctrl Z然后Enter来创建它。让我们将其命名为init.txt -
然后每次您要运行当前目录时
-
最后一条命令会将当前目录保存到
%CD% 变量中
要以编程方式从Turbo C获取当前目录,您需要读取当前目录结构(CDS)。当前目录是第一个67字节的字段,其中包含以空值终止的字符串
要获取第一个CDS的地址,请使用DOS int 21h的52h函数(设置AH = 52h)。通过向第一个地址添加偏移量可以获得后续的CDS。有关更多信息,请阅读
- 当前目录结构(CDS)的格式(数组,LASTDRIVE条目)
- PC Mag 1991年8月
- PC Mag 1993年11月9日
- PC Mag 1991年6月25日
The command method (@phuclv's first answer) (Drawback: A permanent file needs to be maintained)
The assembly method (@phuclv's first answer) (Drawback: I can't really find any way to perform system calls in assembly, it would be great if someone could provide a example and ask some privileged user to edit this answer to remove this info)
The TURBOC method (Since I was anyways writing C90 code, I just used the way I anyways was going to.)
这是示例C90代码,可用于在TURBOC3中获取并执行一些操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<stdio.h> //#include<string.h> void main() { char path[128]; system("cd>__p_"); fscanf(fopen("__p_","r"),"%[^\ ]",path); remove("__p_"); //path variable/array/pointer contains your current path. //printf(path); //strcat(command,path); //char command[128]="cd"; //system(command); } |