使用 VBscript 编码到文件夹中的 return 文件名列表以及每个文件第一行第 35 到 40 位置的 return 文本
Code to return list of file names in a folder and additionally return text from 35th to 40th position on line one each file using VBscript
我正在尝试编写一个脚本来读取文件夹中的所有文件名并将它们列出来,同时读取从第一行开始的第 35 到 45 条文本
示例文件数据
{1:XXXXXXXXXXXXXX0000000000}{2:XXXXXXXXXXXXXXXXX}
{4:
:20:XXXXXXXXXXX
:21:XXXXXXXXXXX
我的代码
Dim objFileSystem,wshShell,MainPath,fileCount,fileLIst,FiletoRead, objFile,strline, Newfile
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set NewFile = objFileSystem.CreateTextFile("c:\test\FileList.txt", True) 'Text file object
Set NewFile = objFileSystem.CreateTextFile("c:\test\FileList.txt", True) 'Text file object
MainPath="Path Location"
rem inputbox("Enter File Location here")
if objFileSystem.FolderExists(MainPath) then
msgbox "control here 1"
FindFileRec MainPath
else
msgbox "Path " & MainPath & "not found"
else if
msgbox "completed"
Function FindFileRec(ThisFolder)
Dim fileName,subFolderobj,subFolderList,Folderobj
Set Folderobj=objFileSystem.GetFolder(ThisFolder)
msgbox "control here 2"
For Each fileName In Folderobj.Files
fileCount=fileCount+1 'update count
UpldateListInTextFile fileName.Name,NewFile
Next 'File
NewFile.Close()
End Function
Function UpldateListInTextFile(sfile, NewFile)
NewFile.WriteLine(sfile)
End function
参见OpenAsTextStream方法。
' VBScript
Const OUT_FILE = "C:\temp\FileList.txt"
Const PATH = "C:\temp\txt"
Dim objFSO, objOutFile, objFolder, objInFile, objTS, str, count
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(OUT_FILE, True)
If objFSO.FolderExists(PATH) then
Set objFolder = objFSO.getFolder(PATH)
For Each objInFile In objFolder.Files
set objTS = objInFile.OpenAsTextStream
str = MID(objTS.readline,35,11)
objOutFile.WriteLine objInFile.name & vbTab & str
objTS.close
count = count + 1
Next
objOutFile.close
msgbox count & " lines written to " & OUT_FILE, vbInformation, "Finished"
Else
msgbox "Path " & PATH & "not found", vbCritical
End If
我正在尝试编写一个脚本来读取文件夹中的所有文件名并将它们列出来,同时读取从第一行开始的第 35 到 45 条文本
示例文件数据
{1:XXXXXXXXXXXXXX0000000000}{2:XXXXXXXXXXXXXXXXX}
{4:
:20:XXXXXXXXXXX
:21:XXXXXXXXXXX
我的代码
Dim objFileSystem,wshShell,MainPath,fileCount,fileLIst,FiletoRead, objFile,strline, Newfile
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set NewFile = objFileSystem.CreateTextFile("c:\test\FileList.txt", True) 'Text file object
Set NewFile = objFileSystem.CreateTextFile("c:\test\FileList.txt", True) 'Text file object
MainPath="Path Location"
rem inputbox("Enter File Location here")
if objFileSystem.FolderExists(MainPath) then
msgbox "control here 1"
FindFileRec MainPath
else
msgbox "Path " & MainPath & "not found"
else if
msgbox "completed"
Function FindFileRec(ThisFolder)
Dim fileName,subFolderobj,subFolderList,Folderobj
Set Folderobj=objFileSystem.GetFolder(ThisFolder)
msgbox "control here 2"
For Each fileName In Folderobj.Files
fileCount=fileCount+1 'update count
UpldateListInTextFile fileName.Name,NewFile
Next 'File
NewFile.Close()
End Function
Function UpldateListInTextFile(sfile, NewFile)
NewFile.WriteLine(sfile)
End function
参见OpenAsTextStream方法。
' VBScript
Const OUT_FILE = "C:\temp\FileList.txt"
Const PATH = "C:\temp\txt"
Dim objFSO, objOutFile, objFolder, objInFile, objTS, str, count
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(OUT_FILE, True)
If objFSO.FolderExists(PATH) then
Set objFolder = objFSO.getFolder(PATH)
For Each objInFile In objFolder.Files
set objTS = objInFile.OpenAsTextStream
str = MID(objTS.readline,35,11)
objOutFile.WriteLine objInFile.name & vbTab & str
objTS.close
count = count + 1
Next
objOutFile.close
msgbox count & " lines written to " & OUT_FILE, vbInformation, "Finished"
Else
msgbox "Path " & PATH & "not found", vbCritical
End If