Link to home
Start Free TrialLog in
Avatar of Adrian Raj
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.

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 

Open in new window

Appreciate your help.
Thanks
Avatar of NVIT
NVIT
Flag of United States of America image

Is vbs required? If not, I can give you a bat/cmd solution instead.
SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adrian Raj
Adrian Raj

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
@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
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.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)
strText = fileList.ReadAll  
fileList.close
arrFileList = Split(strText, vbCrLf)
             
Set objFolder1 = objFSO.GetFolder(strFolder1)

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
@dan
Works like a charm. Thanks for the help and the tip.will do
You're welcome.

Glad I could help!