|
-
Feb 11th, 2005, 10:53 AM
#1
Thread Starter
Hyperactive Member
copy entire folder and sub folders
hi, i am making a program that i would like to copy a folder from one workstation/document server to my network server. how can i make an app copy a folder (E:\documents\ or //A/DOCS$/) to a server (//HOST/DOCS$ or C:\Documents\) to backup documents and overwrite the old files and do this every 10 or 15 mins. i am making this program incase one of my servers brakes down.
Thanks, dandono.
If there is only one perfect person in the universe, does that make them imperfect?
-
Feb 11th, 2005, 11:08 AM
#2
Re: copy entire folder and sub folders
Some APIs are involved so here is a sample:
VB Code:
Option Explicit
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
Private Const FOF_MULTIDESTFILES = &H1
Private Const FOF_CONFIRMMOUSE = &H2
Private Const FOF_SILENT = &H4
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_WANTMAPPINGHANDLE = &H20
Private Const FOF_CREATEPROGRESSDLG = &H0
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_FILESONLY = &H80
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_NOCONFIRMMKDIR = &H200
Private Const FO_MOVE = 1
Private Const FO_COPY = 2
Private Const FO_DELETE = 3
Private Const FO_RENAME = 4
Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
'==========================================================================================
Dim varFOS As SHFILEOPSTRUCT
With varFOS
.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOCONFIRMMKDIR
.wFunc = FO_COPY
.pFrom = strSource
.pTo = strDest
End With
Call SHFileOperation(varFOS)
CopyFolder = (varFOS.fAnyOperationsAborted = 0)
End Function
Private Sub Command1_Click()
CopyFolder "c:\temp\test1", "c:\temp\test2"
End Sub
-
Feb 11th, 2005, 12:05 PM
#3
Re: copy entire folder and sub folders
If the destination folder exists you can just do
VB Code:
Shell "xcopy.exe C:\temp C:\temp2 /E", 1
-
Feb 11th, 2005, 12:06 PM
#4
Frenzied Member
Re: copy entire folder and sub folders
Nice to see the old Dos commands still have their uses.
-
Feb 11th, 2005, 12:42 PM
#5
Thread Starter
Hyperactive Member
Re: copy entire folder and sub folders
i could not get the api version to work but does the shell one copy over network aswell?
If there is only one perfect person in the universe, does that make them imperfect?
-
Feb 11th, 2005, 01:12 PM
#6
Re: copy entire folder and sub folders
I believe so but I have no way to test it.
-
Feb 11th, 2005, 04:54 PM
#7
Re: copy entire folder and sub folders
It doesn't appear to. I even tried mapping the drive to \david on the remote machine, and then copying \test with \test2 in it to \test
xcopy y:\test c:\test
0 files copied.
-
Feb 11th, 2005, 05:00 PM
#8
Re: copy entire folder and sub folders
That sample I've posted works perfectly IF user has sufficient security access: read/write at least. Also you may need to check if source/destination folders exist prior to calling CopyFolder function ...
-
Feb 11th, 2005, 05:58 PM
#9
Re: copy entire folder and sub folders
sorry, i was referring to the xcopy command.
-
Feb 11th, 2005, 07:12 PM
#10
Re: copy entire folder and sub folders
... and I was just answering to this :
i could not get the api version to work ...
-
Feb 11th, 2005, 07:15 PM
#11
Re: copy entire folder and sub folders
Also, XCOPY might not recognize long names so you'll need to convert long path to short (the DOS way):
VB Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Public Function GetShortPath(strFileName As String) As String
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Dim lngRes As Long, strPath As String
'Create a buffer
strPath = String$(165, 0)
'retrieve the short pathname
lngRes = GetShortPathName(strFileName, strPath, 164)
'remove all unnecessary chr$(0)'s
GetShortPath = Left$(strPath, lngRes)
End Function
Private Sub Form_Load()
MsgBox GetShortPath("c:\Program Files\")
End Sub
-
Feb 11th, 2005, 07:30 PM
#12
Re: copy entire folder and sub folders
Nope, I was using \David\Test
-
Feb 11th, 2005, 07:48 PM
#13
Re: copy entire folder and sub folders
Wouldn't know what to tell you then as I like using more robust API solution(s) when aplicable and not those for DOS. Sorry.
-
Feb 12th, 2005, 05:11 AM
#14
Thread Starter
Hyperactive Member
Re: copy entire folder and sub folders
i'm using this code: Shell "xcopy " + txtloc.Text + " " + txthost.Text
it does not seem to work and i am on a user that is a net admin. does it work if it is copying to a windows server 2003 domain controler from a windows xp professional workstation?
If there is only one perfect person in the universe, does that make them imperfect?
-
Feb 12th, 2005, 05:16 AM
#15
Re: copy entire folder and sub folders
I would go with the API version. I fought for quite a while to try to get a batch/cmd file to work, and ran into one problem after another. I finally redid everything using an older API, and I guess that it hasn't been tested, yet.
Usie RhinoBulls example above. It should work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|