我是刚开始编写批处理文件,并且正在尝试实现输出文件,如下所示:
C:\
---Folder1
---files
---files
---Folder2
---files
I also want the path of each file
使用/ tree尝试过,但是我需要文本文件中的输出。我不想使用/ tree,因为这些行会出现。我想将文件解析为数据框。因此,我不需要任何符号或箭头。我需要使用空格。
第一个解决方案基于@Ken White的评论,正如他所说的那样tree /A
,它可以正常工作,并且可以使用默认的Consolas字体在记事本中正确显示。
@echo off
Set "PathFolder=C:\temp"
Set "LogFile=C:\temp\Tree_Result.txt"
Rem simply pipe tree output to skip the two lines in the header
Tree "%PathFolder%" /F /A | more +2>"%LogFile%"
If Exist "%LogFile%" Start "" "%LogFile%"
输出是这样的:
C:\TEMP | 1155.tif | check.txt | filetest.txt | InitJsonInSvc.dat | InitJsonOutSvc.dat | test.txt | Tmp_Output.txt | Tree_Output.txt | Tree_Result.txt | +---Exiland Backup | parametre.ini | \---Test | parametre.ini | +---Exiland Backup | parametre.ini | \---Nouveau dossier b.txt c.txt parametre.ini vide.ini
我在Windows 10(32位)法语版本上创建并测试的第二个解决方案类似于以下混合代码:
<!-- :
@echo off
Title Replace unwanted Characters in the command Tree and save it into file by Hackoo 2019
setlocal enableExtensions enableDelayedExpansion
::ÿþ
set "cp="
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%~a"
if not defined cp set "cp=850"
>nul chcp 65001
Set "PathFolder=C:\temp"
Set "TmpFile=C:\temp\Tmp_Output.txt"
Set "LogFile=C:\temp\Tree_Output.txt"
PowerShell ^
Tree "!PathFolder!" /F ^| Select-Object -Skip 2 ^| Set-Content !TmpFile! -Encoding unicode;
cscript //nologo "%~f0?.wsf" //job:ReplaceString "!TmpFile!" "�" " ">"!LogFile!"
If Exist "!LogFile!" Start "" "!LogFile!"
endlocal
>nul chcp %cp%
exit /b
--->
<job id="ReplaceString">
<script language="Vbscript">
Dim fso,File,Char,ReplaceChar,ReadAll
Set FSO = CreateObject("Scripting.FileSystemObject")
InputFile=WScript.Arguments(0)
Char=WScript.Arguments(1)
ReplaceChar=WScript.Arguments(2)
Set oFile = FSO.OpenTextFile(InputFile, 1, False, -1)
strData = oFile.ReadAll
WScript.echo(Replace(strData,Char,ReplaceChar))
</script>
</job>
所以我得到这样的输出文本:
C:\TEMP 1155.tif check.txt filetest.txt InitJsonInSvc.dat InitJsonOutSvc.dat test.txt Tree_Result.txt Exiland Backup parametre.ini Test parametre.ini Exiland Backup parametre.ini Nouveau dossier b.txt c.txt parametre.ini vide.ini
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句