function get_dir_parent(dir:string;n:integer):string; //n为几级父目录varst:string;i:integer;begin st:=GetCurrentDir; SetCurrentDir(dir); for i:=1 to n do begin ChDir('..'); end; result:=GetCurrentDir; SetCurrentDir(st);//恢
bat 获取当前目录的父目录 @echo off echo batchfile=%0 echo full=%~f0 setlocal for %%d in (%~dp0.) do set Directory=%%~fd echo Directory=%Directory% for %%d in (%~dp0..) do set ParentDirectory=%%~fd echo ParentDirectory=%ParentDirectory% endlocal pause