Copy files based on listbox selection (1 Viewer)

Lochwood

Registered User.
Local time
Today, 08:02
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:
 

Ranman256

Well-known member
Local time
Today, 11:02
Joined
Apr 9, 2015
Messages
4,339
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
 

moke123

AWF VIP
Local time
Today, 11:02
Joined
Jan 11, 2013
Messages
3,852
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?
 

Lochwood

Registered User.
Local time
Today, 08:02
Joined
Jun 7, 2017
Messages
130
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
 

moke123

AWF VIP
Local time
Today, 11:02
Joined
Jan 11, 2013
Messages
3,852
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

  • DestinationFolder.zip
    54.6 KB · Views: 53

Lochwood

Registered User.
Local time
Today, 08:02
Joined
Jun 7, 2017
Messages
130
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

Top Bottom