HondaKillrsx
HondaKillrsx

Reputation: 349

Replacing SubString values with the Replace function

The code below looks in the test folder for any files that have not been accessed in over 5 days, if it finds one it assigns mRoot the file path and then whats NOT WORKING is using the Replace method to look inside the mRoot string for the IP and replace it with the new one, I have it show me what mRoot looks like in a pop up just to make sure it changes(or doesn't). I can't seem to get the IP to change. Can anyone help out? I'm very new to VBS so I'm hoping this is obvious (whether it is doable or not). Thanks.

Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")

sRoot = "\\192.168.1.104\test\" 


today = Date 
Set aFolder = oFileSys.GetFolder(sRoot)
Set aFiles = aFolder.Files      
    For Each file in aFiles
        FileAccessed = FormatDateTime(file.DateLastAccessed, "2")
        If DateDiff("d", FileAccessed, today) > 5 Then
           Set objShell = Wscript.CreateObject("Wscript.Shell")
            mRoot = file
            Call Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")
            objShell.Popup mRoot,, "My Popup Dialogue box"
           'oFileSys.MoveFile file, mRoot
        End If
    Next

Upvotes: 0

Views: 567

Answers (1)

PatricK
PatricK

Reputation: 6433

Try mRoot = Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")

Upvotes: 2

Related Questions