-1

I found this code:

Option Explicit                                                               ' .. Just coz.
Const forReading = 1                                                          ' Set our constants for later.
Const forWriting = 2                                                          ' ....

Dim inputFile, outputFile, fso, fileList, logFile, fileSpec                   ' Dimension our variables

inputFile = "filelist.txt"                                                    ' Our input file
outputFile = "missing.txt"                                                    ' Our output file

Set fso = CreateObject("Scripting.FileSystemObject")                          ' Set up fso
Set fileList = fso.OpenTextFile(inputFile, forReading)                        ' Open our input file for reading
If Not (fso.FileExists(outputFile)) Then fso.CreateTextFile(outputfile)       ' Create output file if it doesn't exist
Set logFile = fso.OpenTextFile(outputFile, forWriting)                        ' Open up our output file for writing later

Do while not fileList.AtEndOfStream                                           ' While we have lines to process do this loop
    fileSpec = fileList.ReadLine()                                            ' Read in line of text as variable fileSpec
    If Not (fso.FileExists(fileSpec)) Then                                    ' If it doesnt exist ....
        logFile.writeline (fileSpec)                                          ' ....Write it out to the output file
    End If 
Loop

fileList.close                                                                ' Clean up
logFile.close   

Here is explanation of that code.

I need one more thing. I need move extra files from default directory (they are not write in filelist.txt) into the new directory. I need in default directory only files who are write in filelist.txt. I don't fully understand that code. I was try remake that code but each time failed.

Community
  • 1
  • 1
Mi1anovic
  • 458
  • 1
  • 4
  • 11

1 Answers1

0

Set problems (union, difference, ...) can be solved with a Dictionary in VBScript.

You have two sets of file names, one from your source file (SetF), one from the files in your default directory (SetD). In your existing loop over SetF, store the the names in a dictionary (DicF). Then add a loop over SetD (DefFolder.Files) and move the files that don't exist in DicF - as in:

>> SetF = Split("A D F G")
>> SetD = Split("B D G H")
>> Set DicF = CreateObject("Scripting.Dictionary")
>> For Each f in SetF
>>     DicF(f) = 0
>> Next
>> For Each f In SetD
>>     If Not DicF.Exists(f) Then
>>        WScript.Echo f
>>     End If
>> Next
>>
B
H

(cf. Compare arrays)

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96