简体   繁体   English

批处理脚本解析目录命令

[英]Batch Script Parsing Dir Command

Hello newbie looking for some help. 您好,新手正在寻求帮助。 I am trying to write a script to search all files and folders in my drive which have a certain identifier. 我正在尝试编写脚本来搜索驱动器中具有特定标识符的所有文件和文件夹。 For example "ID -" 例如“ ID-”

I was using the following to get files and directories listed in a log file: 我使用以下命令获取日志文件中列出的文件和目录:

dir ID * /A:-D-H /B /S >> C:\FileCatalogue.log 2>> C:\FileCatalogue.log
dir ID * /A:D-H /T:C /S >> C:\DirCatalogue.log 2>> C:\DirCatalogue.log

However I want the output to be in 3 tabbed columns: 但是我希望输出在3个选项卡式列中:

FILE {tab} DIR {tab} ID FILE {tab} DIR {tab} ID

ID123 - YYYY - myfile.txt {tab} C:/tmp/tmp {tab} ID123 - YYYY ID123-YYYY-myfile.txt {tab} C:/ tmp / tmp {tab} ID123-YYYY

etc.. 等等..

etc... 等等...

Any help would be greatly appreciated! 任何帮助将不胜感激! Victor 胜利者

尝试这个:

for /f "tokens=1*delims=-" %%a in ('dir /a-d/b ID*') do echo %%a-%%b  %cd%  %%a
@echo off
for /f "delims=" %%A in ('dir /a:-d-h /b /s /t:c ID123*') do for /f "tokens=1,2,* delims=-" %%B in ("%%~nxA") do echo(%%~nxA    %%~dpA  %%B-%%C

Output 产量

ID123 - YYYY - myfile.txt   C:\Users\User\Desktop\  ID123 - YYYY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM