Sign in to follow this  
Followers 0
stev379

Move network drive mappings to new server

1 post in this topic

mappathstest.txt

Hi,

We're moving many old shares to a NetApp server. Some of the old shares will need to connect to new shares with the same name but for reasons too long to explain, some old shares will connect to a folder under a new share with the same name. Confused?

It's like so:

similar to svrs-oldtest.txt

Old share1 \\Server\marketing

Old share2 \\Server\GAD

Old share3 \\Server\Science

similar to mappathstest.txt

New share1 \\NewServer\marketing

New share2 \\NewServer\DEPT\GAD

New share3 \\NewServer\DEPT\Science

With the new shares, the DEPT folder would be shared and the mapping will map to the GAD or Science subfolder. This means different lengths of the strings and more elements in the new share when I turn it into a string then an array. This is why I reversed the strings so I could then use the same element in the array as the share name, then reverse it back to normal to compare.

The script works great, but doesn't stop. I commented out line 33 as it was an attempt to get the script to stop, but I'm concerned that it's stopping it too soon.

I'm looking for suggestions as to why the script continues to loop and how to get it to run to completion.

Thanks for any help or suggestions!!

-Steve

Dim $DrvLtr, $Drv, $DrvNew, $DrvOld, $DrvOldLen, $DrvPath, $DrvShrNew
Dim $i
Dim $FileNew, $FileOld

$DrvLtr = StringSplit("A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,O,Q,R,S,T,U,V,W,X,Y,Z", ",")

$FileNew = FileOpen("mappaths.txt", 0)
$FileOld = FileOpen("svrs-old.txt", 0)


If $FileNew = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
If $FileOld = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $DrvOld = FileReadLine($FileOld)
    If @error = -1 Then ExitLoop
    $DrvOldLen = Stringlen($DrvOld)
    
    $DrvOldPath = StringSplit(_StringReverse($DrvOld), "\")
    For $d = 0 to $DrvOldPath[0]
    $DrvShrOld = (_StringReverse($DrvOldPath[$d]))
    
    While 1
        $DrvNew = FileReadLine($FileNew)
        ;If $DrvNew = "" Then Exit
        $DrvPath = StringSplit(_StringReverse($DrvNew), "\")
        
        $n = 0
        For $n = 0 to $DrvPath[0]       
            $DrvShrNew = (_StringReverse($DrvPath[$n]))
            
            If @error = -1 Then ExitLoop
                $DrvNewLen = StringLen($DrvNew)
                    
                For $i = 0 to 26
                 
                 $Drv = DriveMapGet($DrvLtr[$i] & ":")
                 
                    If $Drv <> "" Then
                        Select
                            
                        Case FileExists($DrvLtr[$i] & ":\")
                        
                            Select
                                ;put stringupper in before both stringrights later on
                            Case StringRight($Drv, stringLen($Drv) - $DrvOldLen) = $DrvShrNew
                        
                                $Drv = $DrvNew
                                DriveMapDel($DrvLtr[$i] & ":")
                                Sleep(500)
                                DriveMapAdd($DrvLtr[$i] & ":", $DrvNew, 1)
                                
                            EndSelect
                            
                        EndSelect
                        
                    EndIf
                    
                Next
             
            Next
            
        Wend
        
    Next

Wend

FileClose($FileNew)
FileClose($FileOld)
MsgBox(0, "Re-Mappings Complete", "Done")

Exit


Func _StringReverse($sString)
   ;==============================================
   ; Local Constant/Variable Declaration Section
   ;==============================================
   Local $sReverse
   Local $iCount
   
   If StringLen($sString) >= 1 Then
      For $iCount = 1 To StringLen($sString)
         $sReverse = StringMid($sString, $iCount, 1) & $sReverse
      Next
      
      Return $sReverse
   Else
      SetError(1)
      Return ""
   EndIf
EndFunc   ;_StringReverse

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0