|
-
Jan 9th, 2008, 09:45 AM
#1
Thread Starter
Addicted Member
[RESOLVED] USB drive backup program
I'm trying to write a program that backs up USB drives.
The program should copy all the files/folders on the USB drive to my harddisk. The most important part is that, the program should still let other processes run while copying the files..
I'm totally blur on this.
Can you please enlighten me
Questions
1. How do I copy files/folders (including subfolders)
2. How do I copy files/folders while still letting other processes run smoothly as usual. (How long it takes to copy is not important)
Last edited by winterslam; Jan 10th, 2008 at 10:08 AM.
-
Jan 9th, 2008, 10:02 AM
#2
Re: USB drive backup program
1. Usb drives register with the system as any other harddrive. So copying to and from usb drives is just the same as you would do from any other drive.
2. Call DoEvents in your code to allow the system to run other processes. e.g. Do copying in loop and call DoEvents after one file/folder is copied.
-
Jan 9th, 2008, 10:06 AM
#3
Thread Starter
Addicted Member
Re: USB drive backup program
How do I go about copying the contents of the drive?
Do I have to use FileSystemObject's CopyFolder method?
-
Jan 9th, 2008, 10:11 AM
#4
Hyperactive Member
Re: USB drive backup program
Last edited by Davadvice; Jan 15th, 2008 at 04:41 AM.
This is Blank
-
Jan 9th, 2008, 10:12 AM
#5
Re: USB drive backup program
There are many ways. But what you are thinking seems to be good enough.
-
Jan 9th, 2008, 10:18 AM
#6
Re: USB drive backup program
This might help in copying folders.
-
Jan 9th, 2008, 10:26 AM
#7
Thread Starter
Addicted Member
Re: USB drive backup program
Thanks for the replies 
The program will be copying several Gigs. The most important part is that the program should give some breathing time for other processes to run simultaneously.
It doesn't matter if it takes a few hours to copy the entire drive byte by byte.. slowly..
It is at least better than copying in 10mins while stopping all the other processes.
I have never tried FileSystemObject though.
Can it handle that?
-
Jan 9th, 2008, 10:47 AM
#8
Thread Starter
Addicted Member
Re: USB drive backup program
I've just found a similar project on planetsourcecode.com
http://www.planetsourcecode.com/vb/s...00810433943032
The only problem is that I can't seem to run other processes smoothly while copying.
-
Jan 9th, 2008, 10:52 AM
#9
Hyperactive Member
Re: USB drive backup program
Last edited by Davadvice; Jan 15th, 2008 at 04:41 AM.
This is Blank
-
Jan 9th, 2008, 11:37 AM
#10
Frenzied Member
Re: USB drive backup program
I doubt it will be more than 4 GB... If I remember right (although i often don't) then 4GB is the largest file size you can have on a FAT formatted disk. Not sure how it works in this case though.
-
Jan 9th, 2008, 11:41 AM
#11
Thread Starter
Addicted Member
Re: USB drive backup program
 Originally Posted by Davadvice
what is the maximum size of an individule file?
you may need to itterate through the folders and recreate the directory structure on the HDD then itterate throgh each file and use Doevents after a certain amount of files have been copied to the HDD.
you have to bear in mind that the FSO is just recreating the copy and paste of explorer (i think)
The files will mostly be mp3s and documents.. so roughly around 4mb on average..
How do I go about making it iterate through each folder and sub-folder as you mentioned?
-
Jan 9th, 2008, 09:23 PM
#12
Thread Starter
Addicted Member
Re: USB drive backup program
I'm almost there..
The program iterates each folder/subfolder and copies file by file.
Should I use DoEvents or Sleep function to give breathing time for other processes?
Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep 2000 ' sleep 2 seconds for every 5 files
Last edited by winterslam; Jan 9th, 2008 at 10:37 PM.
-
Jan 9th, 2008, 09:53 PM
#13
Re: USB drive backup program
 Originally Posted by 03myersd
I doubt it will be more than 4 GB... If I remember right (although i often don't) then 4GB is the largest file size you can have on a FAT formatted disk. Not sure how it works in this case though.
you don't remember correctly. 2GB is the largest size a FAT16 partition can be in 3.1, 95, 98, 2k up to sp2(?). 4GB is the limit for a FAT16 partition from then on. HOWEVER, the fact is that you aren't limited to using FAT on a removable drive. I have NTFS on mine. 2K can format removable media as ntfs. XP can only format them as fat16 and fat32, but you can then run the command-line convert.exe program on them, which is used to convert filesystems to NTFS.
-
Jan 9th, 2008, 10:53 PM
#14
Thread Starter
Addicted Member
Re: USB drive backup program
This is my code
Code:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim fso As New FileSystemObject
Public Sub FolderCopy(ByVal source As String, ByVal destination As String)
Dim objfile As File
Dim objfolder As Folder
DoEvents
For Each objfile In fso.GetFolder(source).Files
DoEvents
On Error Resume Next
If objfile.Name <> "" Then
objfile.Copy destination + "\" + objfile.Name, True
Sleep 100
End If
Next
For Each objfolder In fso.GetFolder(source).SubFolders
DoEvents
On Error Resume Next
If Dir(destination + "\" + objfolder.Name) = "" Then MkDir destination + "\" + objfolder.Name
FolderCopy objfolder.Path, destination + "\" + objfolder.Name
Next
End Sub
Private Sub Command1_Click()
FolderCopy "E:", "C:\Rescued"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set fso = Nothing
End Sub
What exactly does the 'sleep' command do?
Does it pause my program for some milliseconds while allowing other processes to run smoothly?
But I got great results from this code.
The last step is to get the drive letters of the inserted removable drives.
Last edited by winterslam; Jan 10th, 2008 at 12:11 AM.
-
Jan 10th, 2008, 01:58 AM
#15
Re: USB drive backup program
 Originally Posted by winterslam
This is my code
...
What exactly does the 'sleep' command do?
Does it pause my program for some milliseconds while allowing other processes to run smoothly?
But I got great results from this code.
The last step is to get the drive letters of the inserted removable drives.
The sleep command pauses your application for specified time interval. (May not necessarily give time to other processes to run)
The DoEvents command iteriates through the system process queue and executes them one by one. So ensures that all other processes are running simultaneously.
I think in this situation you should use DoEvents because
1. you don't want your application to sleep even if there are no other processes to run.
2. DoEvents ensures that the queue is cleared once before it gives time to your application again.
3. You don't mind your task taking even 1 hour instead of 10 minutes as long as it gives time to other processes on the system. i.e. Processing time is irrelevent.
Pradeep
-
Jan 10th, 2008, 05:53 AM
#16
Hyperactive Member
Re: USB drive backup program
Last edited by Davadvice; Jan 15th, 2008 at 04:41 AM.
This is Blank
-
Jan 10th, 2008, 12:29 PM
#17
Re: [RESOLVED] USB drive backup program
On Topic: This API call will help you determine if it's a removable drive or not:
Code:
Declare Function GetDriveType& Lib "kernel32" Alias "GetDriveTypeA" (ByVal _
nDrive As String)
msgbox getdrivetype("E:\")
Removable drives have their own return code, although you wouldn't be able to tell a jump drive from a usb hard drive.
Completely off topic, but responding to Davadvice's off-topic:
I totally disagree with that. I find it hard to read when you use an ampersand to concantenate. An ampersand is used in dozens of different ways and this is only one of them. Implicitly declaring a variable as long, listing a number as hexidecimal, etc..
Code:
dim a as long, b as long, c as long, d as long, e as long, f as long, g as long, h as long ...
shortens to:
dim a&, b&, c&, d&, e&, f&, g&, h&... and actually fits on one line.
It also forces variables to be a Long
1& + 2&. is faster than 1 + 2 since the values are considered longs.
The only good reason to use it on a string is concantenating a number onto a string. However, if you manage to somehow mis-declare your variable as a string, you won't get an errror! Plus you will end up using it in the wrong place (adding numeric values) and it will give you the wrong result but not give you an error!
a = 1, b = 2
n = a + b 'n = 3
n = a & b' n = 12
the "+" on the other hand can add numbers or strings, but it actually lets you know if you mix them together by generating an error.
But since we aren't allowed to use mathematical operators on strings, what would you suggest we replace the equals sign with? Or the greater/less than? yes, they work on strings too!.
msgbox "a" > "b" will return false
msgbox "a" < "b" will return true
In short, learn to read code written by professional programmers, not shortcut users.
Last edited by Lord Orwell; Jan 10th, 2008 at 12:33 PM.
-
Jan 11th, 2008, 04:05 AM
#18
Hyperactive Member
Re: [RESOLVED] USB drive backup program
this total post is a waste. as the mod edited it.
cheers PEN!!
Personal comments not allowed for certain users but ok for others !!
Last edited by Davadvice; Jan 15th, 2008 at 04:40 AM.
This is Blank
-
Jan 11th, 2008, 09:29 PM
#19
Re: [RESOLVED] USB drive backup program
um, if you were to enclose them in quotes, making them a string, they would be concantenated when using the "+" symbol. I was pointing out that if you make a coding error somewhere else the & symbol will not catch it where a + will. The & converts everything to strings and the + will let you know if one of them isn't a string in the first place. And i personally have 24 years in basic programming. And visual basic is the only one that lets you use the & symbol. I don't see where you said i was being condenscending. I was pointing out that some of us who have been programming for years (but FYI i have only been earning ratings on my posts for the last 6 months because the ratings thing is very new and i was gone for a while but i must be doing SOMETHING right because i was sent a free vbforums button-down shirt that came in the mail today) But i don't expect you to understand that because you gave me a negative rating for disagreeing with you. And you aren't even the thread starter. I explained in detail why plus should be used, and you merely stated "&" should be used did not give a reason besides "i was told it was better". Personal attacks on me and my marriage are not considered good form and are in fact grounds for banning. Please keep this in mind in the future.
I do admit the final line was a little harsh, but you will probably get worse treatment from other members of the forum than one line of text telling you to work on your skills as a code-reader. You recommend a course they don't agree with, and you will find your eyeballs bleeding... Yeah i am a "regular" and i don't consider myself to be professional. Professionals have nothing to do with time in programming. It has everything to do with whether or not you are paid for it, which i am not.
And i didn't even list the best part: + is over four times faster than & at putting strings together (at least on my system) probably due to the fact it converts everything to a string, even things that are strings already.(my system for comparison basis: xp64 multi-core running 64-bit windows xp)
Code:
Private Sub Form_Load()
a = Timer
For cl = 1 To 1000000
jl = x + x + x + x + x + x + x
Next cl
MsgBox " + is " & Timer - a
a = Timer
For cl = 1 To 1000000
jl = x & x & x & x & x & x & x
Next cl
MsgBox " & is " & Timer - a
End Sub
Last edited by Lord Orwell; Jan 11th, 2008 at 10:07 PM.
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
|