正如標題所示,我正在嘗試使用批處理檔案將所有檔案的名稱和批處理檔案所在的父目錄的路徑復制到文本檔案中。我搜索了以前的帖子,但沒有遇到任何解決我問題的帖子。
到目前為止,我可以使用以下標題為dir.bat位于的批處理命令寫入所有檔案名(沒有補丁或檔案夾名稱) C:\Users\Username\Documents\FolderName:
dir /b /a-d > fileslist.txt
這會在找到批處理檔案的同一檔案夾中輸出一個文本檔案:
dir.bat
fileslist.txt
New Text Document - Copy (2).txt
New Text Document - Copy (3).txt
New Text Document - Copy (4).txt
New Text Document - Copy (5).txt
New Text Document - Copy.txt
New Text Document.txt
有沒有辦法在批處理檔案中添加一行,以便文本檔案在開頭或結尾處具有父目錄的路徑,如下所示:
C:\Users\Username\Documents\FolderName
dir.bat
fileslist.txt
New Text Document - Copy (2).txt
New Text Document - Copy (3).txt
New Text Document - Copy (4).txt
New Text Document - Copy (5).txt
New Text Document - Copy.txt
New Text Document.txt
這是我的第一篇文章,所以如果我可以提供更多資訊來幫助指導回復,請告訴我!先感謝您!
uj5u.com熱心網友回復:
您的dir命令未列出與批處理檔案位于同一目錄中的所有檔案。它列出了當前作業目錄中的所有檔案。您很幸運,您用來執行批處理檔案的方法是使用批處理檔案目錄作為當前目錄。
為了正確輸出您需要的內容,我建議使用簡單的一行:
@(For %%G In ("%~dp0.") Do @Echo %%~fG& Echo(& Dir "%~dp0" /B /A:-D) 1>"filelist.txt"
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485735.html
標籤:批处理文件 命令 windows-10
