简体   繁体   English

根据文件名和目录创建文本文件 - 批处理

[英]create text file based on filenames and directory - batch

I have multiple .pdf files located in one directory.我在一个目录中有多个.pdf文件。

Example of the file names in the directory : test score_test score _9999999999_smith.pdf`.目录中的文件名示例: test score_test score _9999999999_smith.pdf`。

I need to parse the file name to be: 9999999999|test score|smith|||||||我需要将文件名解析为: 9999999999|test score|smith|||||||

And I also need to print the location of the file to a text file with an @ symbol at the beginning.而且我还需要将文件的位置打印到以@符号开头的文本文件中。

So it looks like this in the text file: @D:\\TEMP\\test score_test score _9999999999_smith.pdf所以在文本文件中看起来是这样的: @D:\\TEMP\\test score_test score _9999999999_smith.pdf

The file output in the text file would be:文本文件中的文件输出将是:

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

I only got to as far as outputting the directory and file name to a text file.我只需要将目录和文件名输出到文本文件。

Right now I'm just working on adding the @ to the beginning of the directory/filename.现在我正在努力将@添加到目录/文件名的开头。

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

I've tried this:我试过这个:

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

I've tried this:我试过这个:

dir *.pdf /b /s ren *.pdf     "@"????????????????????????????????????????????????????????.pdf >>     C:\temp\test.txt
@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
)

Sample LogFile.txt示例日志文件.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

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

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