[英]Batch - Store output of dir command into variable - directory listing
我需要将整个目录列表存储到一个变量中,然后将所述变量作为参数传递给另一个脚本。 直接或首先将 dir 的输出存储到文本文件,然后执行以下操作:
dir \path\todir > temp.txt
set /p VAR=<temp.txt
但上面只读了一行。 有人可以帮忙吗?
由于您没有向我们提供有关您的最终目标的任何其他信息;
我发布了一些内容,也许会给您任何想法,以便使用如下代码的数组轻松存储变量:
@echo off
set "folder=%userprofile%\Desktop"
setLocal EnableDelayedExpansion
REM Populate the array with existent sub-folders in this folder
for /f "tokens=* delims= " %%a in ('Dir /b /a:d "%folder%"') do (
set /a N+=1
set "Folder[!N!]=%%a"
)
Rem Populate the array with existent files in this folder
for /f "tokens=* delims= " %%a in ('Dir /b /a:-d "%folder%"') do (
set /a M+=1
set "File[!M!]=%%a"
)
::*****************************************************************
:Display_Folders
cls & color 0E
echo Just showing only Folders :
echo(
For /L %%i in (1,1,%N%) do (
echo Folder[%%i] = !Folder[%%i]!
)
echo(
echo Hit any key to show only files :
pause>nul
::*****************************************************************
:Display_Files
cls & color 0B
echo Just showing only Files :
echo(
For /L %%j in (1,1,%M%) do (
echo File[%%j] = !File[%%j]!
)
echo(
echo Hit any key to exit :
Pause>nul & exit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.