Copy files based on listbox selection

Lochwood

Registered User.
Local time
Today, 00:41
Joined
Jun 7, 2017
Messages
130
I have records that have Doc_ID, Doc_Num, Doc_Desc, Hyperlink

Every record has its own filesystem folder based on doc_num and the files within it.. (doc files, pdfs etc) The hyperlink looks at the pdf path within the folder. E:G \\server\docproduction\doc_num123\12345.pdf

My form looks at this query and has a listbox attached showing all the records.

What i am trying to do is have the listbox as a simple multiselect and for each record i highlight, i can click a button that copies all the selected folders to my local computer.

Where do i start?:banghead:
 
Code:
dim sSrc as string, sTarg as string, sName as string
dim vDir 

  'text box holds the target folder
vDir = txtTargetFolder
If Right(vDir, 1) <> "\" Then vDir = vDir & "\"

For i = 0 To Me!lstBox.ListCount-1
    if Me!lstBox.Selected(i) then
       sSrc =  lstBox.ItemData(i) 
       sName = mid(sSrc,instrRev(sSrc,"\")+1)    'get the file name only,no path
       
       sTarg = vDir & sName
       filecopy sSrc, sTarg
    endif
Next
 
When I first looked at this question earlier this morning I had the same solution as Ranman but then noticed " i can click a button that copies all the selected folders to my local computer."

Do you want to copy individual files or copy the whole folder of files?
 
When I first looked at this question earlier this morning I had the same solution as Ranman but then noticed " i can click a button that copies all the selected folders to my local computer."

Do you want to copy individual files or copy the whole folder of files?

Either or Really
 
here's a sample database using filecopy with a multiselect listbox.
Note that if a file with the same name already exists in the destination folder it will be overwritten. I included a delete copies procedure which will delete all the copies in the destination folder.
HTH
 

Attachments

Code:
dim sSrc as string, sTarg as string, sName as string
dim vDir 

  'text box holds the target folder
vDir = txtTargetFolder
If Right(vDir, 1) <> "\" Then vDir = vDir & "\"

For i = 0 To Me!lstBox.ListCount-1
    if Me!lstBox.Selected(i) then
       sSrc =  lstBox.ItemData(i) 
       sName = mid(sSrc,instrRev(sSrc,"\")+1)    'get the file name only,no path
       
       sTarg = vDir & sName
       filecopy sSrc, sTarg
    endif
Next

Got this working great and i can copy the files selected from the listbox. Now heres my next question. At the moment the code is looking at the hyperlink URL and copying the file but ultimately i want to copy all the files within the folder part of the url except any *.doc files. would this be possible?

Heres the code i am currently using.

Private Sub Command11_Click()

Dim sSrc As String, sTarg As String, sName As String
Dim vDir

'text box holds the target folder
vDir = "c:\temp"
If Right(vDir, 1) <> "" Then vDir = vDir & ""


For i = 0 To Me!List9.ListCount - 1
If Me!List9.Selected(i) Then
sSrc = List9.ItemData(i)
sName = Mid(sSrc, InStrRev(sSrc, "")) 'get the file name only,no path

sTarg = vDir & sName
FileCopy sSrc, sTarg
End If
Next

End Sub
 

Users who are viewing this thread

Back
Top Bottom