Complete newbie here so please be gentle :)
See script below which extracts user data from a number of servers. The original array was path1, alt2, alt3 but I have now added the others up to alt8. The script will search its server locations but when it finds one with data to extract it moves on to the new location. What I want to do is, extract data from all the locations. Say the folder had alt3, alt4 and alt6. Rather than just extract data from the first location it finds ie. alt3, then moves on, I want it to check all locations and take whatever data it finds in each for the output text file. Hope that explains it well. I guess i need some sort of AND added to it.
See script below which extracts user data from a number of servers. The original array was path1, alt2, alt3 but I have now added the others up to alt8. The script will search its server locations but when it finds one with data to extract it moves on to the new location. What I want to do is, extract data from all the locations. Say the folder had alt3, alt4 and alt6. Rather than just extract data from the first location it finds ie. alt3, then moves on, I want it to check all locations and take whatever data it finds in each for the output text file. Hope that explains it well. I guess i need some sort of AND added to it.
Code:
Dim fs, f, f1, fc, s, p, fd, fn, intSize, arrTxtArray(), newArray,alt1,alt2,alt3,alt4,alt5,alt6,alt7,alt8
s = ""
p = ""
fd = ""
fn = ""
strMonth = Month(Date)
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
strDay = Day(Date)
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
strYear = Year(Date)
dfoldr = "\\blws03\c$\Users\mayr\Desktop\Report Script\FullReportResults\" & strMonth & strDay & strYear & "\"
foldr = "\\blws03\c$\Users\mayr\Desktop\Report Script\FullReportResults\"
foldr1 = foldr & strMonth & strDay & strYear
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FolderExists(dfoldr) Then
WSCript.Echo "Folder already exists"
Else
fs.CreateFolder(dfoldr)
WSCript.Echo "Folder Created Successfully"
End If
If fs.FolderExists(foldr) Then
If fs.FolderExists(foldr1) Then
WSCript.Echo "Folder already exists"
Else
Set cfoldr = fs.CreateFolder(foldr1)
WSCript.Echo "Folder Created Successfully"
End If
Else
Set cfoldr = fs.CreateFolder(foldr)
Set cfoldr = fs.CreateFolder(foldr1)
End If
set wshShell=wscript.createobject("WSCript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
set serverfile = fso.OpenTextFile("servers.txt",1)
Do Until serverfile.AtEndOfStream
strPath = serverfile.ReadLine
path1 = ("\\" & strPath & "\dragndrop" )
alt1 = ("\\" & strPath & "\dragndrop1" )
alt2 = ("\\" & strPath & "\dragndrop2" )
alt3 = ("\\" & strPath & "\dragndrop3" )
alt4 = ("\\" & strpath & "\WsProfiles" )
alt5 = ("\\" & strpath & "\WsProfiles1" )
alt6 = ("\\" & strpath & "\WsProfiles2" )
alt7 = ("\\" & strpath & "\WsProfiles3" )
alt8 = ("\\" & strpath & "\WsProfiles4" )
wscript.echo "path1 =" & path1
If fs.FolderExists(path1) Then
path1 = path1
ElseIf fs.FolderExists(alt1) then
path1 = alt1
ElseIf fs.FolderExists(alt2) then
path1 = alt2
ElseIf fs.FolderExists(alt3) then
path1 = alt3
ElseIf fs.FolderExists(alt4) then
path1 = alt4
ElseIf fs.FolderExists(alt5) then
path1 = alt5
ElseIf fs.FolderExists(alt6) then
path1 = alt6
ElseIf fs.FolderExists(alt7) then
path1 = alt7
Else path1 = alt8
End If
Set pf = fs.GetFolder(path1)
Set pfc = pf.SubFolders
For Each pf1 in pfc
wscript.echo "pf1 =" & pf1
folderName = pf1.name
wscript.echo folderName
tempfile = foldr1 & "\DDCount" & "ForProfilesOn_" & strpath & "_" & folderName & "_" & strMonth & strDay & strYear & "DateList" & ".txt"
wscript.echo "tempfile = " &tempfile
Set MyFile = fso.CreateTextFile(tempfile, True)
path = pf1
wscript.echo "path = " & path
Call Userdirs(path)
Next
Loop
Sub Userdirs(path)
Set ufs = CreateObject("Scripting.FileSystemObject")
Set uf = ufs.GetFolder(path)
Set ufc = uf.SubFolders
For Each uf1 in ufc
uf2 = uf1.path & "\OMU\DRAG_DROP_Q\FAILED"
wscript.echo uf1.path
If ufs.FolderExists(uf2) Then
newArray = Split (uf1.path, "\", -1, 1)
intSize = 0
Set ufd = fs.GetFolder(uf2)
Set ufn = ufd.files
For Each uf3 in ufn
ReDim Preserve arrTxtArray(intSize)
arrTxtArray(intSize) = uf3.name
intSize = intSize +1
Next
ToMod = uf1.DateLastModified
DateDay = Left(Day(ToMod), 2)
DateMonth = Left(Month((ToMod)), 2)
DYear = Left(Year((ToMod)), 4)
If Len(DateDay) = 1 Then
DateDay = "0" & DateDay
End If
If Len(DateMonth) = 1 Then
DateMonth = "0" & DateMonth
End If
ModSet = DateDay & "/" & DateMonth & "/" & DYear & " " & Right((FormatDateTime(ToMod, 4)), 5)
If intSize = 0 Then
myfile.writeline(newArray(5) & "," & intSize & "," & "0" & "," & "0" & "," & ModSet)
End If
For Each uf3 in ufn
If Len(uf3.Name) = 36 Then
ToCre = uf3.DateCreated
CDateDay = Left(Day(ToCre), 2)
CDateMonth = Left(Month((ToCre)), 2)
CDYear = Left(Year((ToCre)), 4)
If Len(CDateDay) = 1 Then
CDateDay = "0" & CDateDay
End If
If Len(CDateMonth) = 1 Then
CDateMonth = "0" & CDateMonth
End If
CreSet = CDateDay & "/" & CDateMonth & "/" & CDYear & " " & Right((FormatDateTime(ToCre, 4)), 5)
myfile.writeline(newArray(5) & "," & intSize & "," & uf3.Name & "," & CreSet & "," & ModSet)
End If
Next
End If
Next
End Sub