簡體   English   中英

根據文件名和目錄創建文本文件 - 批處理

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

我在一個目錄中有多個.pdf文件。

目錄中的文件名示例: test score_test score _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 var1=@
dir *.pdf /b /s  DO ECHO %var1%*.pdf > C:\temp\test.txt

我試過這個:

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
)

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