Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90224

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

$
0
0

I am trying to write a script that will read all file names in a folder and list them out, Also at the same time read read text 35th to 45th from first line

Sample file data

 {1:XXXXXXXXXXXXXX0000000000}{2:XXXXXXXXXXXXXXXXX}
{4:
:20:XXXXXXXXXXX
:21:XXXXXXXXXXX

My code

 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

Viewing all articles
Browse latest Browse all 90224

Trending Articles