Hi, i have been searching Google for weeks now looking for help on a project, i'm not in school college etc, i am a network admin in a secondary school. Basically i was sick of teachers/pupils losing their pen drives and complaining to us that their work is missing, i set out to create a program to ease the backing up process to ensure this happened less often. i did manage to create a program using 'Get current directory' & 'Copy directory' and it works fine but not to the standard i want. Here is a clip of my current program, pretty neat for a beginner i think.I want the .EXE to sit on the pendrive and extract everything to a backup folder when it's run.
Because (h:/) or whatever the letter, is a DRIVE, copy directory method wont work. Hopefully someone can help me in the right direction in how to copy contents of a drive, please bare in mind i'm a beginner and only code in my spare time.
Thank you in advance.
Liam.
Copying files from a PenDrive
Page 1 of 111 Replies - 1435 Views - Last Post: 21 March 2012 - 02:25 AM
Replies To: Copying files from a PenDrive
#2
Re: Copying files from a PenDrive
Posted 19 March 2012 - 07:00 PM
I don't know if I understand correctly...you have .exe application on your pen drive, you want to copy all files from pendrive when you run this application from pendrive?
#3
Re: Copying files from a PenDrive
Posted 19 March 2012 - 09:38 PM
I Think This Is What You Are After. Just Copy And Paste To A Button And Your Set. You Can Change The Destination To Your Liking. This Will Send Everything To Your MyDocuments Folder And Will Create A New Directory Called "Back Up Files". This Code Will Overwrite Everthing If The Files Already Exist.
Hope This Helps SomeWhat! Don't Forget To Give Me A Plus If This Works.
Dim Source As String = My.Computer.FileSystem.CurrentDirectory 'This Will Copy Every File\Directory From Where The Program Is Run
Dim Destination As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Backup Of Files\" 'This Is The Destination Folder (My Documents\Backup Of Files\*.*)
'Loop All Files And Folders To Copy Everything
For Each File As String In My.Computer.FileSystem.GetFiles(Source, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
'Copy Everything To Destination Directory
My.Computer.FileSystem.CopyFile(File, String.Concat(Destination, Microsoft.VisualBasic.Right(File, Microsoft.VisualBasic.Len(File) - 3)), True)
Next
Hope This Helps SomeWhat! Don't Forget To Give Me A Plus If This Works.
This post has been edited by PNJLj: 19 March 2012 - 09:39 PM
#4
Re: Copying files from a PenDrive
Posted 20 March 2012 - 01:00 AM
Thank you! this code did work, it does lag abit, but i'll try iron out the problems, i'm sorry i didnt make my first post clear Sela007, if you watch my YouTube clip attached to the first post you can see the program i have made, it works fine when placed in a folder, but when placed on the pen drive i get the error 'H:/ is not a valid directory' or something like that. PNJLj's code seems to be working and i'm going to adapt it around my program! thanks guys.
#5
Re: Copying files from a PenDrive
Posted 20 March 2012 - 01:39 AM
no worries, glad i could help.
anything else just post and someone will check it.
anything else just post and someone will check it.
#6
Re: Copying files from a PenDrive
Posted 20 March 2012 - 02:35 AM
This site is great, my program runs great now! just as i wanted! thanks a bunch!
#7
Re: Copying files from a PenDrive
Posted 20 March 2012 - 07:20 AM
Thanks for the help.
that works fine now i want to see if i can improve the program more.
I want to create a program that runs silently in the background and knows when a pen drive is plugged in and then copies its content to a back up folder on the desktop.
Currently my program recognises when a device is plugged in and kick starts the 'copy' code. However the copy code is designed to copy files from where it is executed and in this case will not work. Does anybody have a idea on how i can get it to copy from the pen drive without adding files to the pen itself.
i hope i made this post understandable.
Code;
Thanks guys
liam.
that works fine now i want to see if i can improve the program more.
I want to create a program that runs silently in the background and knows when a pen drive is plugged in and then copies its content to a back up folder on the desktop.
Currently my program recognises when a device is plugged in and kick starts the 'copy' code. However the copy code is designed to copy files from where it is executed and in this case will not work. Does anybody have a idea on how i can get it to copy from the pen drive without adding files to the pen itself.
i hope i made this post understandable.
Code;
Public Class Form1
Private WM_DEVICECHANGE As Integer = &H219
Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = &H19
DBT_CONFIGCHANGED = &H18
DBT_CUSTOMEVENT = &H8006
DBT_DEVICEARRIVAL = &H8000
DBT_DEVICEQUERYREMOVE = &H8001
DBT_DEVICEQUERYREMOVEFAILED = &H8002
DBT_DEVICEREMOVECOMPLETE = &H8004
DBT_DEVICEREMOVEPENDING = &H8003
DBT_DEVICETYPESPECIFIC = &H8005
DBT_DEVNODES_CHANGED = &H7
DBT_QUERYCHANGECONFIG = &H17
DBT_USERDEFINED = &HFFFF
End Enum
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Me.Hide()
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
NotifyIcon1.ShowBalloonTip(500, "PenDriveBackup", "Backing up your files to Desktop!", ToolTipIcon.Info)
'---------------------------- Copy Code Starts ---------------------------------------------------------
Dim Source As String = My.Computer.FileSystem.CurrentDirectory 'This Will Copy Every File\Directory From Where The Program Is Run
Dim Destination As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Backup Of Files\" 'This Is The Destination Folder (My Documents\Backup Of Files\*.*)
'Loop All Files And Folders To Copy Everything
For Each File As String In My.Computer.FileSystem.GetFiles(Source, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
'Copy Everything To Destination Directory
My.Computer.FileSystem.CopyFile(File, String.Concat(Destination, Microsoft.VisualBasic.Right(File, Microsoft.VisualBasic.Len(File) - 3)), True)
Next
'--------------------------- Copy code ends -------------------------------------------------------------
NotifyIcon1.ShowBalloonTip(500, "PenDriveBackup", "Succesfully backed up your files to Desktop!", ToolTipIcon.Info)
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
MsgBox("USB device is just taken out")
End Select
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Hide()
End Sub
End Class
Thanks guys
liam.
#8
Re: Copying files from a PenDrive
Posted 20 March 2012 - 12:41 PM
you could try and Add a Textbox so that the user can enter in their own PenDrive Location. and then another textbox so they can send to where they want. there are a few ideas, but gotta go for now, will check back later. Good Luck.
Liam: - Where did u find all the &H codes? i have been looking everywhere but cannot find them. Any suggestions?
Liam: - Where did u find all the &H codes? i have been looking everywhere but cannot find them. Any suggestions?
This post has been edited by PNJLj: 20 March 2012 - 12:44 PM
#9
Re: Copying files from a PenDrive
Posted 20 March 2012 - 01:11 PM
PNJLj, i had the code from a previous project, i might have found some code i can adapt, i'll have a mess and post the final code.
as for the text box idea i had that in mind but i'm trying to go for a unique minimal/no user interaction
thanks
as for the text box idea i had that in mind but i'm trying to go for a unique minimal/no user interaction
thanks
#10
Re: Copying files from a PenDrive
Posted 20 March 2012 - 04:59 PM
So you know how to copy files, program recognizes when pen drive is plugged, so where is the problem? you don't know how to get drive path?
#11
Re: Copying files from a PenDrive
Posted 20 March 2012 - 05:20 PM
claretrobbo, on 20 March 2012 - 07:20 AM, said:
Currently my program recognises when a device is plugged in and kick starts the 'copy' code. However the copy code is designed to copy files from where it is executed and in this case will not work.
in this case you just need to change 'source'.
Dim Source As String = 'new drive path
Dim Destination As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Backup Of Files\" 'This Is The Destination Folder (My Documents\Backup Of Files\*.*)
'Loop All Files And Folders To Copy Everything
For Each strFile As String In My.Computer.FileSystem.GetFiles(Source, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
Dim strFileName As String = System.IO.Path.GetFileName(strFile) ' get file name from file path
My.Computer.FileSystem.CopyFile(strFile, Destination & strFileName)' copy
Next
#12
Re: Copying files from a PenDrive
Posted 21 March 2012 - 02:25 AM
Thanks guys1 i did notice my error and changed it before reading your post, i have got the program to read the drive letter of the plugged in device and assign it the the 'Source'.
thanks anyway guys.
liam.
thanks anyway guys.
liam.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|