2017-01-09 60 views
-2

我有多个.pdf位于一个目录中的文件。基于文件名和目录创建文本文件 - 批次

目录:测试score_test分数_9999999999_smith.pdf`文件名称的示例。

我需要解析的文件名是:9999999999|test score|smith|||||||

而且我还需要打印文件的位置到一个文本文件开头的@符号。

所以它看起来像这样的文本文件:@D:\TEMP\test score_test score _9999999999_smith.pdf

在文本文件中的文件输出为:

9999999999|test score|smith||||||| 
@D:\TEMP\test score_test score _9999999999_smith.pdf 

我只有去尽可能输出目录和文件名称到一个文本文件。

现在我只是在将@添加到目录/文件名的开头。

dir /s/b *.pdf > C:\temp\test.txt 

我已经试过这样:

@echo off 
set [email protected] 
dir *.pdf /b /s DO ECHO %var1%*.pdf > C:\temp\test.txt 

我已经试过这样:

dir *.pdf /b /s ren *.pdf  "@"????????????????????????????????????????????????????????.pdf >>  C:\temp\test.txt 
+0

问题问我们为**推荐或找到一本书,工具,软件库,教程或其他非现场资源**,因为它们倾向于吸引自以为是的答案和垃圾邮件,因此无法用于Stack Overflow。相反,[描述问题](http://meta.stackoverflow.com/questions/254393)以及迄今为止已经做了什么来解决它。 – nyedidikeke

+0

命令'for' resp。 'for/f'可以做你想做的事。你的问题有点含糊 - 两个字符串'测试分数'是否总是相等,如果不是,哪一个可以选择输出? – LotPings

+0

谢谢。测试分数并不总是相同的。我很抱歉,我需要从文件名中提取第一个_之后的第二个测试分数或名称。 – user7395572

回答

0
@Echo off&SetLocal EnableExtensions 
PushD "C:\path\to\your\pdffolder" 
Set "FileOut=X:\path\to\LogFile.txt" 
:: initially clear Logfile 
Type Nul >"%FileOut%" 
:: first for enumerates the pdfs, second for /f parses the name 
:: to tokens %%A .. %%D delimited by underscore 
For %%F in (*.pdf) do For /f "tokens=1-4 delims=_" %%A in ("%%~nF" 
) Do (
>>"%FileOut%" Echo:%%C^|%%B^|%%D^|^|^|^|^|^|^| 
>>"%FileOut%" Echo:@%%F 
) 

样品LOGFILE.TXT

8888888888|test score |miller||||||| 
@test score_test score _8888888888_miller.pdf 
9999999999|test score |smith||||||| 
@test score_test score _9999999999_smith.pdf 
7777777777|test score |baker||||||| 
@test score_test score _7777777777_baker.pdf 
相关问题