Adrian Raj
asked on
Input past end of file vbs script
Hi Everyone,
I am new to vbscript
Trying for hours to fix the script.
Basically what I am trying to do is
1) To get the filenames from the folder specified
2) Use the filenames from the folder and compare with the names listed in a .txt file and write the missing filename that is not present to the log file.(output.txt)
This is what i have done.
Thanks
I am new to vbscript
Trying for hours to fix the script.
Basically what I am trying to do is
1) To get the filenames from the folder specified
2) Use the filenames from the folder and compare with the names listed in a .txt file and write the missing filename that is not present to the log file.(output.txt)
This is what i have done.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const forReading = 1
logName = "Output.txt"
Set logFile = objFSO.CreateTextFile(logName, True)
inputFile = "a.txt"
strFolder1 = InputBox("Enter Source Folder Path :")
Set fileList = objFSO.OpenTextFile(inputFile, forReading)
Set objFolder1 = objFSO.GetFolder(strFolder1)
Set files = objFolder1.Files
For each objFile in files
fileName = objFile.Name
fileSpec = fileList.ReadLine()
If not (fileName = fileSpec) Then
logFile.writeline (fileName)
End If
next
fileList.close
logFile.close
Appreciate your help.Thanks
Is vbs required? If not, I can give you a bat/cmd solution instead.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@ nvit
Thanka for replying.Yes vbs is required because I have already done the vice versa of the script where file listing is compared against the filename in the folder and return the missing filename from the file list, so m trying to complete this script and combine both. Sort of a vlookup via script. Thanks for the help
Thanka for replying.Yes vbs is required because I have already done the vice versa of the script where file listing is compared against the filename in the folder and return the missing filename from the file list, so m trying to complete this script and combine both. Sort of a vlookup via script. Thanks for the help
ASKER
@dan
Thanks for replying. Ok I will try to google how to pass the file into a string. Thanks for the suggestion. Will let you know if it works
Thanks for replying. Ok I will try to google how to pass the file into a string. Thanks for the suggestion. Will let you know if it works
ASKER
I have pass the file into a string and below is my code, however I am only getting the last filename in the folder specified that does not match the filelist. I know I am close, just need a little bit tweaking. Please help.
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const forReading = 1
logName = "Output.txt"
Set logFile = objFSO.CreateTextFile(logN ame, True)
inputFile = "a.txt"
strFolder1 = InputBox("Enter Source Folder Path :")
Set fileList = objFSO.OpenTextFile(inputF ile, forReading)
strText = fileList.ReadAll
fileList.close
arrFileList = Split(strText, vbCrLf)
Set objFolder1 = objFSO.GetFolder(strFolder 1)
Set files = objFolder1.Files
For each objFile in files
fileName = objFile.Name
Next
For each strFile in arrFileList
If not (fileName = strFile) Then
logFile.writeline (fileName)
End If
Next
logFile.close
Set objFSO = CreateObject("Scripting.Fi
Const forReading = 1
logName = "Output.txt"
Set logFile = objFSO.CreateTextFile(logN
inputFile = "a.txt"
strFolder1 = InputBox("Enter Source Folder Path :")
Set fileList = objFSO.OpenTextFile(inputF
strText = fileList.ReadAll
fileList.close
arrFileList = Split(strText, vbCrLf)
Set objFolder1 = objFSO.GetFolder(strFolder
Set files = objFolder1.Files
For each objFile in files
fileName = objFile.Name
Next
For each strFile in arrFileList
If not (fileName = strFile) Then
logFile.writeline (fileName)
End If
Next
logFile.close
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It helps if you write what you want in plain English before writing any code.
The problem would be something like this:
For each of the files found in the folder, test if it's present in the txt file. If not, append it to the log.
That will stop you from writing the second for loop...
The problem would be something like this:
For each of the files found in the folder, test if it's present in the txt file. If not, append it to the log.
That will stop you from writing the second for loop...
ASKER
@dan
Works like a charm. Thanks for the help and the tip.will do
Works like a charm. Thanks for the help and the tip.will do
You're welcome.
Glad I could help!
Glad I could help!