I am new to VB scripting, and I was trying to find a way to:
- Read a list of file names written as lines of text inside a particular text file.
- Check if those files exist in the same directory as the script.
- Write the name of the files that do not exist to an output file (missing.txt)
From my research, it seems that a good approach would be to use FSO and read the entire text file, creating an array, then looping through to check if the file exists in the directory, and then logging to "missing.txt" if it doesn't.
However, doing it this way, wouldn't there be a type mismatch because the file name in the .txt is a string and the files in the directory themselves are objects?
How would I compare that? I can understand this conceptually, but I have no idea where to start with the syntax.
Thank you for your help.
As you have stated that you are new to vbscript, and you appear to be new to Stack Overflow, I thought I would try to offer you some assistance.
It is not necessary for you to store the entire file as an array. All you need to do is process your input file line by line as text: check if each line of text exists as a filename.
Let's assume the following details for our example:
filelist.txt {The file that will contain the listing of files to find}
Directory Listing {The folder you will be running the script from}
Our example
The
filelist.txt
file containsfile1.txt
file2.txt
file3.txt
file7.txt
.The directory does not contain
file3.txt
orfile7.txt
.Our expected output from this script based on these parameters is as follows:
missing.txt {The resultant output file that lists missing files}
The Script
Here's a script to help you achieve this (I have added comments off to the far right of each relevant line):
I hope this helps you. Have a nice day. :)