Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i map a network drive and copy folder

Status
Not open for further replies.

veenma

Technical User
Jan 31, 2003
9
0
0
CH
Hi all,

I need to map a network drive,
Delete a folder containing files on this network drive,
Copy a folder from my local drive to this network drive,
and disconnect.

Could someone help me?

Thanks for advising me
 
If you use UNC paths you should not need to map but the syntax is below for several different ways to do it ( clipped out of a sample login script ).

Here are the pieces for mapping a network drive:
Code:
On Error Resume Next
Dim strUserName
Dim GroupObj
Dim UserObj
Dim UserGroups
Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject("WScript.Network")

While strUserName = ""
 strUserName = WSHNetwork.UserName
Wend

  ' maps a letter to hidden share based on user name
WSHNetwork.MapNetworkDrive "U:", "\\RUBY\" + strUserName + "$"

'*****************************************************************
'*************  Map drive for DATA Directory  ********************
'*****************************************************************
WSHNetwork.MapNetworkDrive "N:", "\\RUBY\DATA"

'*****************************************************************
'*************  Map drive for Specific Groups!   *****************
'*****************************************************************


'Get User Object
Set UserObj = GetObject("WinNT://FillInYourDomainName/" & strUserName)

UserGroups=""
For Each GroupObj In UserObj.Groups 
  UserGroups=UserGroups & "[" & GroupObj.Name & "]"
Next

UserGroups = Ucase(UserGroups)

'*************  Map J: drive for ECS members OR Shams users *****************
'Check if member of group
Select Case true
  case InStr(UserGroups,"[" & "ECS" & "]") > 0
    WSHNetwork.MapNetworkDrive "J:", "\\RUBY\Applications"

  case InStr(UserGroups,"[" & "TRANSCRIPTION" & "]") > 0 
      WSHNetwork.MapNetworkDrive "J:", "\\ONYX\Shams"
End Select

WSHNetwork.RemoveNetworkDrive "j:" ' will remove mapped drive

'etc etc

Here are some pieces for copying a folder
Code:
Dim fso
Dim source
Dim destination
Dim overwrite
Dim force

Set fso = CreateObject("Scripting.FileSystemObject")

source = "c:\test"
' with UNC
destination = "\\NetworkServerName\sharename\pathname"
' or with drive mapped to \\NetworkServerName\sharename
destination = "J:\pathname"

overwrite = True
force = True

If fso.FolderExists(destination) Then
  fso.DeleteFolder destination, force
End If
fso.CopyFolder source, destination, overwrite
 
Thanks to you PGTuner, i had found a way of doing it but yours is more precise and really answers my needs.
Thanks once again for your precious help.

;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top