Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 父目录批处理_Batch File_Directory_Parent - Fatal编程技术网

Batch file 父目录批处理

Batch file 父目录批处理,batch-file,directory,parent,Batch File,Directory,Parent,在我之前的一份报告中,向我提供了以下代码: @echo on setlocal EnableDelayedExpansion set "digits=8" set mypath=%~dp0 cd /d "%~dp0" rem delete old list from current even if read only del /f list.txt rem Assemble the factor with the proper number of digits set "factor=1"

在我之前的一份报告中,向我提供了以下代码:

@echo on
setlocal EnableDelayedExpansion

set "digits=8"
set mypath=%~dp0
cd /d "%~dp0"

rem delete old list from current even if read only
del /f list.txt

rem Assemble the factor with the proper number of digits
set "factor=1"
for /L %%i in (1,1,%digits%) do set "factor=!factor!0"

rem Accumulate size of all extensions in 2 groups of %digits% digits each
for %%a in (*.*) do (
   set "size=%factor%%%~Za"
   set /A "low[%%~Xa]+=1!size:~-%digits%!-factor, carry=low[%%~Xa]/factor, 
low[%%~Xa]%%=factor"
   set "size=%%~Za"
   set "size=!size:~0,-%digits%!"
   set /A "high[%%~Xa]+=carry+size"
)

rem Show results
for /F "tokens=2,3 delims=[.]=" %%a in ('set high[') do (
   if %%b neq 0 (
      set "low=%factor%!low[.%%a]!"
      echo %%a %%b!low:~-%digits%! bytes >>"%mypath%\list.txt"
   ) else (
      echo %%a !low[.%%a]! bytes >>"%mypath%\list.txt"
   )
)
现在,我试图让它在创建列表时搜索父目录


我仍然希望最终的测试文件被保存到本地目录,所以没有任何更改

那么
cd/d“%~dp0..”
怎么样?我是批处理新手,所以我不太清楚你的意思。。如果你想说我应该用“cd/d”%~dp0..”替换“cd/d”%~dp0..”的话,那是行不通的。del命令也需要一个路径,但是你要求的是父目录-
cd/d“%~dp0..”
就是这样做的。正如(*.*)中%%a的
所做的(
迭代当前目录,然后向上执行相同的一级操作。如前所述,
cd/d“%~dp0..”
del/f“%~dp0list.txt”
是您需要进行的更改。您可以选择删除不必要的
set mypath=%~dp0
并更改
“%mypath%\list.txt”
“%~dp0list.txt”
,或者将其保留,并将其更改为
“%mypath%list.txt”
。此外,如果您在链接问题中使用了此选项,则有将目录传递给它的基本说明(您可以将父目录拖放到其中)!