2012-07-19 96 views
0

我需要一個腳本來爲我的csv文件中的每一行創建一個空的文本文件。VBS - csv到文本文件

我的CSV文件數據的3列...

Along Came Polly,2003,192 
American Beauty,1999,146 
American Cousins,2007,286 
An American Crime,2007,179 

我想創建一個命名爲每個行和格式化爲一個空文本文件....

Along Came Polly (2003) Slot 192.txt 
American Beauty (1999) Slot 146.txt 
American Cousins (2007) Slot 286.txt 
An American Crime (2007) Slot 179.txt 

人幫助我,因爲我沒有vb的經驗。

謝謝 添

回答

0

這就是你可能會尋找

Option Explicit 
Dim objFSO, objTextFile, strFileLine,objFile,strFileName 



' Create the File System Object 
Set objFSO = CreateObject("Scripting.FileSystemObject") 


Set objTextFile=objFSO.OpenTextFile("C:\Documents and Settings\amolc\Desktop\SO\Sample.csv") ''Mention Path of your CSV file here 


Do Until objTextFile.atEndOfStream 
    strFileLine =objTextFile.ReadLine 
    strFileLine =Split(strFileLine,",") 
    strFileName=strFileLine(0)&" ("&strFileLine(1)&") "&"Slot "&strFileLine(2)&".txt" 
    Set objFile = objFSO.CreateTextFile("C:\Documents and Settings\amolc\Desktop\SO\"&strFileName) ''Hardcoded path is the location where you can store your text file 
Loop 
+1

這相當奏效4M01。 – user1539145 2012-07-20 16:31:20

+0

如果它幫助你,你可以接受它作爲答案! – Amol 2012-07-20 17:30:25