Code:
Option Explicit 'Force explicit variable declaration
'declare variable
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim sourceFolder : sourceFolder = Array ("D:\sourceFolder Een","D:\sourceFolder Twee")
Dim targetFolder : targetFolder = Array("D:\Dest Een","D:\Dest Twee")
Dim targetFolderFTP : targetFolderFTP = Array ("D:\ftp1","D:\ftp2")
Dim file, fileWithOutExtension, RFcounter, sFolder, folder, files, filesIdx, ReadFolder,input, quotes, quotestwee
quotes=""""
'cals function LoopAllFiles to trigger the process
LoopAllFiles()
'Calls function to loop true the files
Function LoopAllFiles()
FOR RFcounter = 0 to Ubound(sourceFolder)
sFolder = sourceFolder(RFcounter)
Set folder = FSO.GetFolder(sFolder)
Set files = folder.Files
For each filesIdx IN files
file= filesIdx.name
fileWithOutExtension = Left(file, InStrRev(file,".") - 1)
'<<---- for testing, can be deleted!! ----- >>
'wscript.echo("test1")
'wscript.echo(dubble(sourceFolder(RFcounter) & "\" & file))
'wscript.echo(fso.FileExists(dubble(sourceFolder(RFcounter) & "\" & file)))
'<<---- till here --->
'HELP THIS DOESN"T WORK PROPERLY
If (FSO.FileExists(dubble(sourceFolder(RFcounter) & "\" & file))) Then
deleteFilesFromtargetFolder()
End if
If fso.GetExtensionName(UCase(file)) = "TIF" Then
Select Case RFCounter
Case "0"
methodOne()
WScript.Sleep 2000 'wacht 2 seconde ivm de importer
Case "1"
methodTwo()
WScript.Sleep 2000 'wacht 2 seconde ivm de importer
End Select
End if
moveBestanden()
WScript.Sleep 2000 'wacht 2 seconde ivm de importer
Next
NEXT
End function
Function dubble(input)
dubble = quotes & input & quotes
End Function
'Delete files in targetFolder if exists
Sub deleteFilesFromtargetFolder()
wscript.echo("Deleting files...")
If (fso.FileExists(dubble(targetFolder(RFcounter) & "\" & file))) Then
fso.DeleteFile(dubble(targetFolder(RFcounter) & "\" & file)) 'Deletes tif file in target folder
End if
End Sub
'Movefiles
Sub moveBestanden()
wscript.echo("copy files")
fso.MoveFile dubble(sourceFolder(RFcounter) & "\" & file), dubble((targetFolder(RFcounter)) & "\" & file) 'Moves files <----- this doesn't work properly
End Sub
Sub methodOne()
wscript.echo("copy files to fto CK")
fso.CopyFile dubble(sourceFolder(RFcounter) & "\" & file), dubble(targetFolderFTP(RFcounter) & "\" & file) 'Moves files <----- this doesn't work properly
End Sub
Sub methodTwo()
wscript.echo("copy files to ftp TH")
fso.CopyFile dubble(sourceFolder(RFcounter) & "\" & file), dubble(targetFolderFTP(RFcounter)) & "\" & file 'Moves files <----- this doesn't work properly
End Sub