- 如何替换?使用父文件夹名称,而不是路径
<Name>VEH_"?"</Name>
- 从文件名创建列表并添加前缀和后缀
- 文件名必须放在"是
<Item><Name>?</Name><Variations type="NULL"/></Item>
- 我不知道如何正确地完成第一步或第三步
代码:
Dim fso, folder, files, OutputFile
Dim strPath
Const ForReading = 1
Const ForWriting = 2
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Define folder we want to list files from
strPath = "D:folderimg"
Set folder = fso.GetFolder(strPath)
Set files = folder.Files
' Create text file to output test data
Set OutputFile = fso.CreateTextFile("Vehichlespawnwhead.txt", True)
OutputFile.WriteLine("<Name>VEH_"parentfoldername"</Name>")
OutputFile.WriteLine("")
' Loop through each file
For each item In files
' Output file properties to a text file
OutputFile.WriteLine("<Item><Name>(item.Name)</Name><Variations type=""NULL""/></Item>")
OutputFile.WriteLine("")
Next
' Close text file
OutputFile.Close
现在如果运行文本文件将读取
<Name>VEH_"parentfoldername"</Name>
<Item><Name>(item.Name)</Name><Variations type="NULL"/></Item>
<Item><Name>(item.Name)</Name><Variations type="NULL"/></Item>
- 我的目标是
<Name>VEH_img</Name>
<Item><Name>file1</Name><Variations type="NULL"/></Item>
<Item><Name>file2</Name><Variations type="NULL"/></Item>
文件1和文件2不应包含其扩展
抱歉在全新中出现格式问题
欢迎来到SO。您非常接近!
您所需要做的就是使用folder.Name
(第18行(,并在For循环中使用fso.GetBaseName(item.Name)
(第25行(;当然,也要使用适当的字符串连接。
例如:
Dim fso, folder, files, OutputFile
Dim strPath
Const ForReading = 1
Const ForWriting = 2
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Define folder we want to list files from
strPath = "D:folderimg"
Set folder = fso.GetFolder(strPath)
Set files = folder.Files
' Create text file to output test data
Set OutputFile = fso.CreateTextFile("Vehichlespawnwhead.txt", True)
OutputFile.WriteLine("<Name>VEH_" & folder.Name & "</Name>")
OutputFile.WriteLine("")
' Loop through each file
For each item In files
' Output file properties to a text file
OutputFile.WriteLine("<Item><Name>" & fso.GetBaseName(item.Name) & "</Name><Variations type=""NULL""/></Item>")
OutputFile.WriteLine("")
Next
' Close text file
OutputFile.Close
享受吧。