VBS合并一個檔案夾裡的TXT的實現代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:Const ForReading = 1 'VBS的這句不能少。
dim xint,xinlu,jiuw
dim objfso,objoutputfile,f,fx
dim objTextFile,strtext
Set objFSO = CreateObject("Scripting.FileSystemObject") '建立FSO對象
jiuw = inputbox("請輸入源檔案夾所在的路徑(含檔案夾名稱)","請輸入多個TXT檔案夾所在位置")

if objFSO.folderexists(jiuw) then
set f = objFSO.getfolder(jiuw) '檔案所在位路徑
else
msgbox "路徑錯誤,請重新輸入"

end if
xinlu = inputbox("請輸入新的TXT所在的路徑(不含書名),如果省略——即直接不輸入焦點確定或取消,則預設是建立在源檔案夾同一層位置","新的TXT儲存位置")

if objFSO.folderexists(xinlu) or len(xinlu) = 0 then
xint = inputbox("請輸入新書名的名字","新書名")
if len(xint)>0 then
xint = xinlu & xint
Set objOutputFile = objFSO.CreateTextFile( xint &".txt") '建立名為output的新的TXT,可以修改為你要的名稱.txt
else
msgbox "沒有輸入內容,請重新輸入"
end if
else
msgbox "路徑錯誤,請重新輸入"

end if
For Each fx In f.Files '迴圈寫入常值內容
Set objTextFile = objFSO.OpenTextFile(fx, ForReading) '找開檔案
strText = objTextFile.ReadAll '讀取全部
objTextFile.Close '關閉開啟的檔案
objOutputFile.WriteLine strText '在output.txt寫入 文本 內容
Next

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.