|
-
May 26th, 2010, 09:26 AM
#1
Thread Starter
Member
[RESOLVED] HELP with check box
I am new to VB and coding to start this off..
I have an automated bat file that backs up select data on PC.
example of first couple lines
@echo off
:: variables
set drive=H:\
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
echo ### Backing Up Files...
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\%folder%\Favorites"
this creates a dated folder and backs up the users "Favorites" if you will. then i have a list of other specific files that are backed up.
I have created this

I now need help with the if then statements..
Once the user selects what they want then i need "Start Backup" t run the selected code.
I have a couple ideas but im not 100% sure on how it works, do i have to logged in a bat file then have it executed after the user is done? if so how do i do this?
please help..
-
May 26th, 2010, 10:06 AM
#2
Re: HELP with check box

What produces the window in that picture?
BTW I deleted your other thread since it was a duplicate.
-
May 26th, 2010, 10:08 AM
#3
Thread Starter
Member
Re: HELP with check box
visual basic? lol
running in debugging mode.
-
May 26th, 2010, 10:14 AM
#4
Re: HELP with check box
So what does the bat file have to do with it? I assume you have the code for the app that produces that window so just add code to it to copy whatever is selected.
-
May 26th, 2010, 10:26 AM
#5
Thread Starter
Member
Re: HELP with check box
well i have "some code" that does what i want, its assigning it to each bottom, then creating the if then statement that i am having problems with..
Like once i hit start i want the app to see what is selected then preform each action, like all in one.
I will then have a status bar incorporated somehow.
-B
-
May 26th, 2010, 10:31 AM
#6
Re: HELP with check box
What version of Visual Basic are you using?
-
May 26th, 2010, 10:32 AM
#7
Thread Starter
Member
-
May 26th, 2010, 10:35 AM
#8
Re: HELP with check box
I kinda figured you were using VB.NET because that doesn't look like a VB6 and Earlier window.
I have moved your thread over to the .NET section. Any coding help you got in the VB6 section wouldn't have worked in your program.
-
May 26th, 2010, 10:43 AM
#9
Thread Starter
Member
Re: HELP with check box
ahh sorry for the mix up and thank you.
-
May 26th, 2010, 10:54 AM
#10
Fanatic Member
Re: HELP with check box
So you're wanting to test if a check box is checked, then run code appropriate to it's state?
Code:
If Checkbox1.Checked Then
''Do Some Work
End If
If Checkbox2.Checked Then
''Do Other Work
End If
For each check box you would need to check its checked state and then run the code if it meets your conditions. I would, however, test the state of the "full backup" check box first, if that one is checked then there is no need to check the others.
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
May 26th, 2010, 11:37 AM
#11
Re: HELP with check box

Code:
Public Class Form1
Dim whCB As New ChkBoxTrack
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = whCB.toStringCB
If whCB.IsOn(_cbCHK.allCB) Then
'all on
ElseIf whCB.Getb = _cbCHK.noCBchked Then
'none checked
Else
If whCB.IsOn(_cbCHK.cb1) Then
Debug.WriteLine("1")
End If
If whCB.IsOn(_cbCHK.cb2) Then
Debug.WriteLine("2")
End If
If whCB.IsOn(_cbCHK.cb3) Then
Debug.WriteLine("3")
End If
If whCB.IsOn(_cbCHK.cb4) Then
Debug.WriteLine("4")
End If
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles CheckBox1.CheckedChanged, _
CheckBox2.CheckedChanged, _
CheckBox3.CheckedChanged, _
CheckBox4.CheckedChanged
Dim cb As CheckBox = DirectCast(sender, CheckBox)
Select Case cb.Name
Case "CheckBox1"
If cb.Checked Then whCB.SetB(_cbCHK.cb1) Else whCB.ClearB(_cbCHK.cb1)
Case "CheckBox2"
If cb.Checked Then whCB.SetB(_cbCHK.cb2) Else whCB.ClearB(_cbCHK.cb2)
Case "CheckBox3"
If cb.Checked Then whCB.SetB(_cbCHK.cb3) Else whCB.ClearB(_cbCHK.cb3)
Case "CheckBox4"
If cb.Checked Then whCB.SetB(_cbCHK.cb4) Else whCB.ClearB(_cbCHK.cb4)
End Select
Debug.WriteLine(whCB.toStringCB)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'in case the default checkbox state is not off
For Each c In Me.Controls
If TypeOf c Is CheckBox Then
DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
End If
Next
End Sub
End Class
Class ChkBoxTrack
Private _myCB As _cbCHK
'set the bit
Public Function SetB(ByVal WhBox As _cbCHK) As _cbCHK
Me._myCB = Me._myCB Or WhBox
End Function
'clear the bit
Public Function ClearB(ByVal WhBox As _cbCHK) As _cbCHK
Me._myCB = Me._myCB And (WhBox Xor _cbCHK.allCB)
End Function
'test the bit
Public Function IsOn(ByVal WhBox As _cbCHK) As Boolean
If (Me._myCB And WhBox) = WhBox Then Return True Else Return False
End Function
'show on bits as string
Public Function toStringCB() As String
Return Me._myCB.ToString
End Function
'get the setting
ReadOnly Property Getb() As _cbCHK
Get
Return Me._myCB
End Get
End Property
End Class
<FlagsAttribute()> _
Public Enum _cbCHK As Integer
noCBchked = 0
cb1 = 1 << 1
cb2 = 1 << 2
cb3 = 1 << 3
cb4 = 1 << 4
allCB = cb1 Or cb2 Or cb3 Or cb4
End Enum
-
May 26th, 2010, 11:52 AM
#12
Thread Starter
Member
Re: HELP with check box
this is what i have now
HTML Code:
Public Class Form1
Dim whCB As New ChkBoxTrack
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles start.Click
Label1.Text = whCB.toStringCB
If whCB.IsOn(_cbCHK.allCB) Then
'all on
ElseIf whCB.Getb = _cbCHK.noCBchked Then
'none checked
Else
End If
If whCB.IsOn(_cbCHK.cb1) Then
Debug.WriteLine("1")
End If
If whCB.IsOn(_cbCHK.cb2) Then
Debug.WriteLine("2")
End If
If whCB.IsOn(_cbCHK.cb3) Then
Debug.WriteLine("3")
End If
If whCB.IsOn(_cbCHK.cb4) Then
Debug.WriteLine("4")
End If
If whCB.IsOn(_cbCHK.cb5) Then
Debug.WriteLine("5")
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mydocuments.CheckedChanged, _
desktop.CheckedChanged, _
favorites.CheckedChanged, _
nethood.CheckedChanged, _
miscoutlook.CheckedChanged
Dim cb As CheckBox = DirectCast(sender, CheckBox)
Select Case cb.Name
Case "mydocuments"
If cb.Checked Then whCB.SetB(_cbCHK.cb1) Else whCB.ClearB(_cbCHK.cb1)
Case "desktop"
If cb.Checked Then whCB.SetB(_cbCHK.cb2) Else whCB.ClearB(_cbCHK.cb2)
Case "favorites"
If cb.Checked Then whCB.SetB(_cbCHK.cb3) Else whCB.ClearB(_cbCHK.cb3)
Case "nethood"
If cb.Checked Then whCB.SetB(_cbCHK.cb4) Else whCB.ClearB(_cbCHK.cb4)
Case "miscoutlook"
If cb.Checked Then whCB.SetB(_cbCHK.cb5) Else whCB.ClearB(_cbCHK.cb5)
End Select
Debug.WriteLine(whCB.toStringCB)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'in case the default checkbox state is not off
For Each c In Me.Controls
If TypeOf c Is CheckBox Then
DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
End If
Next
End Sub
End Class
Class ChkBoxTrack
Private _myCB As _cbCHK
'set the bit
Public Function SetB(ByVal WhBox As _cbCHK) As _cbCHK
Me._myCB = Me._myCB Or WhBox
End Function
'clear the bit
Public Function ClearB(ByVal WhBox As _cbCHK) As _cbCHK
Me._myCB = Me._myCB And (WhBox Xor _cbCHK.allCB)
End Function
'test the bit
Public Function IsOn(ByVal WhBox As _cbCHK) As Boolean
If (Me._myCB And WhBox) = WhBox Then Return True Else Return False
End Function
'show on bits as string
Public Function toStringCB() As String
Return Me._myCB.ToString
End Function
'get the setting
ReadOnly Property Getb() As _cbCHK
Get
Return Me._myCB
End Get
End Property
End Class
<FlagsAttribute()> _
Public Enum _cbCHK As Integer
noCBchked = 0
cb1 = 1 << 1
cb2 = 1 << 2
cb3 = 1 << 3
cb4 = 1 << 4
cb5 = 1 << 5
allCB = cb1 Or cb2 Or cb3 Or cb4 Or cb5
End Enum
added another button, now i see that what buttons are selected are displayed in the label.
I now need to add functions to each one of the "cb1, 2, 3, ext" then be able to run them all while selecting start.
can anyone lend another helping hand?
Each one of the check boxes is going to be pointed to a select location on the users computer.
please help
-Brandon
Last edited by littlejob; May 27th, 2010 at 12:08 PM.
-
May 26th, 2010, 03:24 PM
#13
Thread Starter
Member
Last edited by littlejob; May 27th, 2010 at 12:08 PM.
-
May 27th, 2010, 01:21 PM
#14
Thread Starter
Member
Re: HELP with check box
UPDATE
i found this on another forum
HTML Code:
If Checkm.Value = vbChecked Then
FileCopy "C:\POS\ZDEFLTS.BTR", "C:\BACKUP\MONDAY\ZDEFLTS.BTR"
End If
End Sub
not sure what is the variable, or the button name, and how do i make it apply to my code? im a little stumped on where exactly to put this.
-Brandon
-
May 27th, 2010, 02:00 PM
#15
Re: HELP with check box
I started this for you, but you need to finish it. Just take a look at the way that I did things. It should give you a good head-start.
vb Code:
Public Class Form1 Private Sub BackupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupButton.Click ' ' Test if the My Documents Checkbox is true, if it is copy all the files ' You should use a variable in the GetFiles method. ' If MyDocumentsCheckbox.Checked = True Then For Each file As String In IO.Directory.GetFiles("path to user's 'My Documents' folder or variable") My.Computer.FileSystem.CopyFile(file, "H:\MyDocuments", False) Next End If ' ' Check to see if the desktop checkbox is checked or not. If it is copy the ' the files from the desktop to some folder on the h:\ ' If DesktopCheckbox.Checked = True Then For Each DesktopItem As String In IO.Directory.GetFiles("path to the user's desktop folder") My.Computer.FileSystem.CopyFile(DesktopItem, "H:\DesktopFiles", False) Next End If ' so and so forth, you may want to think about a way to compress the files into one archive. ' I run a backup program and I use SharpZipLib to put everything in a ZIP archive. It will also ' gzip and other compression formats. Just google it and you will get some information. If you need ' more help, please let us know. End Sub End Class
-
May 27th, 2010, 02:23 PM
#16
Thread Starter
Member
Re: HELP with check box
thank you A LOT. i ahve been trying to do this for a while.
I am running into an error thogh when trying to execute the app.
"IOException was unhandled."
"The file 'H:\test\favorites' already exists."
when in fact it does not.. then it crashes out..i do see that the folder test was created but no favorites.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles start.Click
If mydocuments.Checked = True Then
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
My.Computer.FileSystem.CopyFile(file, "H:\test\favorites", False)
Next
End If
End Sub
and yes...i know that the mydocuments chkbox is backing up favorites..just using as an example.
thanks again
-
May 27th, 2010, 02:31 PM
#17
Re: HELP with check box
Code:
My.Computer.FileSystem.CopyFile("SRC", "DST", True)
-
May 27th, 2010, 02:34 PM
#18
Re: HELP with check box
 Originally Posted by littlejob
thank you A LOT. i ahve been trying to do this for a while.
I am running into an error thogh when trying to execute the app.
"IOException was unhandled."
"The file 'H:\test\favorites' already exists."
when in fact it does not.. then it crashes out..i do see that the folder test was created but no favorites.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles start.Click
If mydocuments.Checked = True Then
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
My.Computer.FileSystem.CopyFile(file, "H:\test\favorites", False)
Next
End If
End Sub
and yes...i know that the mydocuments chkbox is backing up favorites..just using as an example.
thanks again
Change this line:
.net Code:
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
To:
.net Code:
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites\")
-
May 27th, 2010, 02:45 PM
#19
Re: HELP with check box
 Originally Posted by mbutler755
Change this line:
.net Code:
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
To:
.net Code:
For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites\")
Use this one instead
.net Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
'
' Check to see if the directory exists. If it does not, create it
'
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("p:\1050")
If folderExists = False Then
My.Computer.FileSystem.CreateDirectory(folderExists)
End If
'
' Parse out the path from the filename and copy the files.
'
For Each DesktopFile As String In IO.Directory.GetFiles("c:\1050", "*.*")
My.Computer.FileSystem.CopyFile(DesktopFile, "p:\1050\" & My.Computer.FileSystem.GetName(DesktopFile))
Next
'
' I tested this one and it works perfectly
'
End If
End Sub
End Class
-
May 27th, 2010, 02:46 PM
#20
Thread Starter
Member
Re: HELP with check box
Did what you tried matt,
ArgumentException was unhandled
"The given file path ends with a directory separator character.
Parameter name: destinationFileName"
hmm..
and with this code
Code:
My.Computer.FileSystem.CopyFile("SRC", "DST", True)
does this copy folders or just specific files?
-Brandon
-
May 27th, 2010, 02:50 PM
#21
Re: HELP with check box
 Originally Posted by littlejob
Did what you tried matt,
ArgumentException was unhandled
"The given file path ends with a directory separator character.
Parameter name: destinationFileName"
hmm..
and with this code
Code:
My.Computer.FileSystem.CopyFile("SRC", "DST", True)
does this copy folders or just specific files?
-Brandon
hmmmmmm.
-
May 27th, 2010, 03:05 PM
#22
Re: HELP with check box
You can also change the method to CopyDirectory and copy multiple directories. Take a look at the method and let me know if you need help.
-
May 27th, 2010, 03:18 PM
#23
Thread Starter
Member
Re: HELP with check box
its been a long day...
the method you posted earlier worked the "use this one instead"
however. If you run the backup again when the file is already there it error-ed out.
Forgetting this, i changed to directory? i think below
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles start.Click
'
' Check to see if the directory exists. If it does not, create it
'
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
If folderExists = False Then
My.Computer.FileSystem.CreateDirectory(folderExists)
End If
'
' Parse out the path from the filename and copy the files.
'
For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*")
My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites" & My.Computer.FileSystem.GetName(DesktopFile))
Next
'
' I tested this one and it works perfectly
'
End Sub
says it cannot find file.
another question 2
"("C:\Documents and Settings\godboubs\Favorites", "*.*")"
does this mean pull all file types? not folder? does this have to be changed as well?
-Brandon
-
May 27th, 2010, 03:22 PM
#24
Re: HELP with check box
In this first line of your program type
Option Strict On
Code:
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
If folderExists = False Then
My.Computer.FileSystem.CreateDirectory(folderExists) '<<<<< create the true or false directory
-
May 27th, 2010, 03:25 PM
#25
Re: HELP with check box
Again, you are missing the last slash before the GetNames method.
Change this:
vb Code:
For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*") My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites" & My.Computer.FileSystem.GetName(DesktopFile)) Next
To This:
vb Code:
For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*") My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites\" & My.Computer.FileSystem.GetName(DesktopFile)) Next
Last edited by mbutler755; May 27th, 2010 at 03:25 PM.
Reason: bold was jacked up
-
May 27th, 2010, 03:30 PM
#26
Thread Starter
Member
Re: HELP with check box
You guys reply really fast, lol
I too noticed this and it did not change anything.
"Could not find directory 'C:\Documents and Settings\godboubs\Favorites\Desktop.ini'."
HTML Code:
My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites\" & My.Computer.FileSystem.GetName(DesktopFile))
points here ^
-
May 27th, 2010, 03:36 PM
#27
Re: HELP with check box
You have to change the For Each line also. You are going to be looking for directories instead of files.
vb Code:
For Each folder As String In IO.Directory.GetDirectories("this is the source") My.Computer.FileSystem.CopyDirectory(folder, "h:\whatever\" & My.Computer.FileSystem.GetName(folder)) Next End Sub
-
May 27th, 2010, 03:45 PM
#28
Re: HELP with check box
I have a backup program. It basically creates a process that is
xcopy sourcedir destdir /C/Y/E/H/R/I
-
May 28th, 2010, 07:24 AM
#29
Thread Starter
Member
Re: HELP with check box
OK day 2 begins...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles start.Click
'
' Check to see if the directory exists. If it does not, create it
'
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
If folderExists = False Then
My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
End If
'
' Parse out the path from the filename and copy the files.
'
For Each folder As String In IO.Directory.GetDirectories("C:\Documents and Settings\godboubs\Favorites", "*.*")
My.Computer.FileSystem.CopyDirectory(folder, "h:\test\favorites\" & My.Computer.FileSystem.GetName(folder))
Next
End Sub
FIRST
Got this working, thanks again for your help however i ran across a couple different things. First the contents of "Favorites in this case (all the URL's) do not get copied, just the sub folders in "Favorites" then the links inside those sub folders.
SECOND
When i run the app a second time after it partially backs up the folder i get an IOException error, "could not complete operation on some files and directories. See the data property of the exception for more details"
THIRD (UPDATE) - figured this part out...

My application looks like this, the code is ran after i click button, i need for it to determine what is selected above first...then run the script according to the users selection.
Code:
If MyDocumentsCheckbox.Checked = True Then
FOURTH
I want to back up the current user logged in files. I know in a batch file it was something along the line of "%USERPROFILE%\Favorites"
not sure how to do in this new greatness im learning
Thanks
Last edited by littlejob; May 28th, 2010 at 08:13 AM.
-
May 28th, 2010, 08:13 AM
#30
Re: HELP with check box
Please post your code for the favorites. You will probably need to run 2 For Each loops. One loop for the folders & and sub-directory files and the other just for files.
-
May 28th, 2010, 08:18 AM
#31
Thread Starter
Member
Re: HELP with check box
 Originally Posted by mbutler755
Please post your code for the favorites. You will probably need to run 2 For Each loops. One loop for the folders & and sub-directory files and the other just for files.
Code:
If mydocuments.Checked = True Then
'
' Check to see if the directory exists. If it does not, create it
'
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
If folderExists = False Then
My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
End If
'
' Parse out the path from the filename and copy the files.
'
For Each folder As String In IO.Directory.GetDirectories("C:\Documents and Settings\godboubs\Favorites", "*.*")
My.Computer.FileSystem.CopyDirectory(folder, "h:\test\favorites\" & My.Computer.FileSystem.GetName(folder))
Next
End If
and yes i know i have it coded for the my docs chk box...
-
May 28th, 2010, 08:35 AM
#32
Re: HELP with check box
Underneath your folder For Each, you will need another one to copy the files.
vb Code:
For Each FavFile as String in IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites","*.*") My.Computer.FileSystem.CopyFile(FavFile,"H:\test\favorites\" & My.Computer.FileSystem.GetName(FavFile)) Next
-
May 28th, 2010, 08:45 AM
#33
Re: HELP with check box
Code:
'two test folders
Dim fromF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test1"
Dim toF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test2"
Dim sw1s As String = " /C/Y/E/H/R/I"
'define command
Dim theCMD As String = "xcopy"
'define comand arguments
Dim theARG As String = """" & fromF & """" & " " & """" & toF & """" & sw1s
'define process and info for it
Dim proc As New Process()
Dim procSI As New ProcessStartInfo()
'set info for command
procSI.FileName = theCMD
procSI.Arguments = theARG
procSI.CreateNoWindow = False
procSI.UseShellExecute = True
proc.StartInfo = procSI
proc.Start()
-
May 28th, 2010, 08:50 AM
#34
Thread Starter
Member
Re: HELP with check box
 Originally Posted by mbutler755
Underneath your folder For Each, you will need another one to copy the files.
vb Code:
For Each FavFile as String in IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites","*.*")
My.Computer.FileSystem.CopyFile(FavFile,"H:\test\favorites\" & My.Computer.FileSystem.GetName(FavFile))
Next
a little confused, what you have looks the same as what i have? another question what does that "FavFile" represent?
-
May 28th, 2010, 09:04 AM
#35
Re: HELP with check box
It is different. The first For Each loop is using the GetDirectories method. The second one, that I just wrote is using the GetFiles method. One For Each loop is getting files, the other is getting directories and the directory's sub-files.
FavFile is just a string representation of each file within the Favorites folder.
A much easier way of doing this would be to copy the Favorites directory in its entirety. This would be much better than copying the directories within the Favorites directory and then the files. If you want to copy everything anyways, you might as well just copy the top line directory. You can accomplish this by using the My.Computer.FileSystem.CopyDirectory method.
Last edited by mbutler755; May 28th, 2010 at 09:19 AM.
-
May 28th, 2010, 09:19 AM
#36
Re: HELP with check box
 Originally Posted by dbasnett
Code:
'two test folders
Dim fromF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test1"
Dim toF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test2"
Dim sw1s As String = " /C/Y/E/H/R/I"
'define command
Dim theCMD As String = "xcopy"
'define comand arguments
Dim theARG As String = """" & fromF & """" & " " & """" & toF & """" & sw1s
'define process and info for it
Dim proc As New Process()
Dim procSI As New ProcessStartInfo()
'set info for command
procSI.FileName = theCMD
procSI.Arguments = theARG
procSI.CreateNoWindow = False
procSI.UseShellExecute = True
proc.StartInfo = procSI
proc.Start()
When I did my backup program I started off just like you are. Build a directory list, and copy each directory to the backup location. When I thought I was done, I wasn't. I finally implemented the xcopy and have been happy ever since (I don't remember what error sent me over the edge).
So, the above code can be implemented easily as a sub that takes two folders as args. Just remember it is here.
-
May 28th, 2010, 09:25 AM
#37
Re: HELP with check box
This works perfectly to copy ALL of the favorites:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Favorites.Checked = True Then Dim folderExists As Boolean folderExists = My.Computer.FileSystem.DirectoryExists("h:\favorites") If folderExists = False Then My.Computer.FileSystem.CreateDirectory(folderExists) End If Try My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\favorites", "h:\favorites", True) Catch ex As ApplicationException MsgBox(ex.Message, MsgBoxStyle.Exclamation) End Try End If End Sub
-
May 28th, 2010, 09:40 AM
#38
Fanatic Member
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
May 28th, 2010, 10:03 AM
#39
Thread Starter
Member
Re: HELP with check box
i get an IO exception error stating that the file allready exists..but it does not exits, nor does it create the file.
-
May 28th, 2010, 10:09 AM
#40
Re: HELP with check box
 Originally Posted by littlejob
i get an IO exception error stating that the file allready exists..but it does not exits, nor does it create the file.
Post the code and the error.
Are you using the code from post #37?
Last edited by mbutler755; May 28th, 2010 at 10:09 AM.
Reason: added info
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
|