Help move files

DooDaa

New member
Joined
Jul 5, 2008
Messages
3
Programming Experience
Beginner
Hi all! I'm extremely new to VB. I have VB Enterprise 6 and VB .NET 2003 Standard. I play a pc game online and have been TRYING to code up a small program for players to use to move the map, sound & texture files from the mod folders to the main game folders. However, I'm a VB & VB .NET coding dummy in the truest sense of the word. My knowledge is EXTREMELY basic when it comes to coding in VB & VB .NET.

Here is the first problem; I have managed to call up the FolderBrowserDialog, select a folder and upon clicking OK, have that folder address appear in the text box next to the Browse buttons. That part works fine. However, upon clicking the Run button in VB .NET to test the program in Run Time, the Output/Debug list displays this;

'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
'KpMapMover': Loaded 'C:\Documents and Settings\DooDaa\My Documents\Visual Studio Projects\KpMapMover\KpMapMover\bin\KpMapMover.exe', Symbols loaded.
'KpMapMover.exe': Loaded 'c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'KpMapMover.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.
'KpMapMover.exe': Loaded 'c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.

Are these problems that need fixing/Debugging? How? Help me please!

Secondly, I then need to write the code attached to the Move button that will move all files and sub-folders from the selected Source folder to the selected Destination Folder. I know it can be done in VB .NET coz i've seen File.Move listed in the MSDN info. But I'm so stupid with VB & VB .NET coding that I just cant get a grasp on understanding the VB & VB .NET language.

Here is what I have in the way of coding this program so far. I know, it's extremely small right now as far as coding goes. I just need some help with this one really badly. All I have coded so far is the 2 browse buttons and the Exit button.

VB.NET:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub

    Private Sub Source_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Source.Click
        FolderBrowserDialog1.ShowNewFolderButton = False
        FolderBrowserDialog1.ShowDialog()
        TextBox1.Text = FolderBrowserDialog1.SelectedPath
    End Sub

    Private Sub Dest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dest.Click
        FolderBrowserDialog1.ShowNewFolderButton = False
        FolderBrowserDialog1.ShowDialog()
        TextBox2.Text = FolderBrowserDialog1.SelectedPath
    End Sub
End Class

I hope I have put this post in the right place on this forum. If not, I appologize. I am new here. Thanks to those who can & do help me.
 

Attachments

  • KPMapMover.jpg
    KPMapMover.jpg
    69.1 KB · Views: 47
Last edited:
The messages in your quote box is just information about the loading of your project assembly and .Net references, "symbols" is for debugging.

To move a folder and all content:
VB.NET:
IO.Directory.Move("C:\temp\sourceFolder", "C:\temp\destinationFolder")
There is also the My namespace with many useful features, for example My.Computer.FileSystem.MoveDirectory methods.
 
If that's all it is, then why is it that when I click the Exit button during runtime testing, or I click the Stop button on the VB .NET 2003 toolbar to end the runtime testing, it lags during the programs End procedure (if i have tested the Browse buttons in the program I am building). YET! If I haven't tested the Browse buttons and just start the program up and click on the Exit button, the program shuts down like normal? There's something I am either not doing or have done incorrectly to cause this issue.

I presume that since you didn't make comment about my coding done so far, that you find no fault in my coding (as simple as if may be)?

Additionally, will that command for moving files and folders you mentions allow for the selection and moving of more than one folder and contents in the one time? Or will this require a different or additional snippet of code?

My apologies for my lack of knowledge. I really appreciate your assistance. Thank you!
 
Last edited:
It takes some time to wire down the debugging symbols, but with VB2003 not more than 3 seconds on my old machine, if this time is higher for you it could be due to a even slower computer than mine. I highly recommended that you go for VB2008, it is a much better and faster IDE in many aspects, also including nice new language features and the additions of several newer versions of the .Net library. Try the free Express for learning, you won't miss anything to the full pay versions.

For the code I only answered your question though I saw the errors, if you had seen all the bad beginner coding posted you would soon realize it is impossible to pick on everything we more experienced coders see could be improved, it would have taken ages that is better spent helping more troubled users getting through the next problem. Another reason is one of the template school exercises is exactly "describe all errors and problems with the given code and propose solutions". This is also something people learn better along the way than being hit to ground for each post they make.

When you show a dialog you should only act if the dialog returns OK, why would you change the path if user cancelled the dialog? This is easy to code since ShowDialog method is a function that returns the value you inquire. The code will look something like this:
VB.NET:
If Me.FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
    Me.SourceLabel.Text = Me.FolderBrowserDialog1.SelectedPath
End If
Notice I used a well-named Label instead of a Textbox. You should not give a user a Textbox if you don't intend them to edit the text, which in this case is inappropriate and obviously can lead to later errors in code execution unless you add code to handle non-existing typed paths. An exception is the read-only textbox to allow for text copy, but that is another topic.

You write code for ShowNewFolderButton, why waste time writing this code when you can just doubleclick the ShowNewFolderButton property in designer to set the value to False? Utilize the visual designers whenever you can, because they generate correct code way faster than you can type, with just a few mouse actions hundreds of lines of code may be generated.

You should not use End statement for reasons outlined in help documentation, instead use Close method or in some cases Application.Exit method. You will also notice a faster closing from debugging since the debugger now will get notified about the close instead of deducting that your application has crashed and close itself down after a short while.

The Move/MoveDirectory method moves one folder including all files/subfolders content.
 
My computer is not that slow. It's a Dual Core Intel processor with 2gb ram, 320gb SATA HDD, 512mb nVidia graphics card. I think that's more than adequate for the job, don't you?

I had to do a reformat just recently because of a stupid program I installed on my computer (Bit Defender). Anyway, after reformatting and reinstalling everything, it seems the lagging problem was part of the problems Bit Defender caused my computer.

Anyway, what I need to know now is;

1) What do I need to change the Folder/File move code to so that it will allow me to select more than one folder for moving? Eg:

Folder --
| SubFolder1 * How can I select (only) all 3 SubFolders for moving
| SubFolder2 at once but not move the main Folder as well?
| SubFolder3

2) How should I code it so that the IO.Directory.Move("Dest", "Source") move code will be able to call up the Dest & Source functions rather than putting specific directories in the IO.Directory.Move("Dest", "Source")?

I'm not sure if I explained that clearly enough, but I hope I have. As far as I'm aware, I need to add some form of Public Dim statements? Perhaps I'm wrong? I can't work it out. It confuses me. I appreciate your assistance with this. Below is what I have so far RE my coding;

VB.NET:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Windows Form Designer Generate Code

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Source
        If Me.FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
            Me.txtSource.Text = Me.FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim Dest
        If Me.FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
            Me.txtDest.Text = Me.FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        IO.Directory.Move("Dest", "Source")
    End Sub
End Class
 
Do you mean to move all sub folders of selected path, but not the parent folder itself? Use IO.Directory to get all it's directories and do a Move for each.
 
Back
Top