Results 1 to 7 of 7

Thread: Special Directory's Not Working..

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Unhappy Special Directory's Not Working..

    im currently working on a project, which requires to download files from the internet and copy them to certain directory's... i've done the downloading part but i can't seem to get the directorys working.....
    the directory's are "special" E.G. Appdata Program Files ETC, and well when i tried just using %appdata% it seemed to create a new directory NAMED %appdata% rather than actually goto appdata... so after some searching i managed to whip up a code but theres something wrong with it... but im not sure what.... please help also im not the best a VB so some complicated stuff i may not understand

    Look at the attachment to see what the error is
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Special Directory's Not Working..

    The problem is that you are assigning the folder path to a variable and then not using that variable. Anything INSIDE the double quotes is literal text. If you want to use a String variable then it must be OUTSIDE the double quotes. Try running this code to see the difference:
    Code:
    Dim str1 As String = "Hello"
    Dim str2 As String = "World"
    
    MessageBox.Show("str1 &  & str2")
    MessageBox.Show(str1 & " " & str2)
    Last edited by jmcilhinney; Feb 9th, 2012 at 03:40 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Re: Special Directory's Not Working..

    Quote Originally Posted by jmcilhinney View Post
    The problem is that you are assigning the folder path to a variable and then not using that variable. Anything INSIDE the double quotes is literal text. If you want to use a String variable then it must be OUTSIDE the double quotes. Try running this code to see the difference:
    Code:
    Dim str1 As String = "Hello"
    Dim str2 As String = "World"
    
    MessageBox.Show("var1 &  & var2")
    MessageBox.Show(var1 & " " & var2)
    like i said im abit slow... im not quite sure what im meant to be running outside the quotes...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Special Directory's Not Working..

    Sorry, I made an error in that code so it wouldn't run. I've fixed it now. Run the code I provided, look at the results it produces, look at the difference in the code and it should be fairly clear from what I said in my previous post what the principle is that my code is demonstrating and how you can apply that to your own code to fix your error.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Re: Special Directory's Not Working..

    oh yeah i see what you mean... however i tried replacing and now its aggrivating me... i can't seem to intergrate it with my code correctly ;/ it keeps scrweing up no matter which way i format it.....

    Here was one attempt:

    vb Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.         Dim fileP As String
    3.         fileP = My.Computer.FileSystem.SpecialDirectories.Desktop
    4.         Dim str1 As String = FileCopy(fileP / "Test.bat", fileP / "Test Folder")
    5.         Dim str2 As String = "Moved!"
    6.  
    7.         MessageBox.Show("str1 &  & str2")
    8.         MessageBox.Show(str1 & "File Moved" & str2)
    9.     End Sub
    10. End Class

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Special Directory's Not Working..

    try this:

    vb Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.     Dim fileP As String
    3.     fileP = My.Computer.FileSystem.SpecialDirectories.Desktop
    4.     Dim source As String = fileP & "\Test.bat"
    5.     Dim destination As String = fileP & "\Test Folder\Test.bat"
    6.     FileCopy(source, destination)
    7.  
    8.     MessageBox.Show(String.Format("'{0}' File Copied to '{1}'", source, destination))
    9. End Sub

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Re: Special Directory's Not Working..

    Quote Originally Posted by .paul. View Post
    try this:

    vb Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.     Dim fileP As String
    3.     fileP = My.Computer.FileSystem.SpecialDirectories.Desktop
    4.     Dim source As String = fileP & "\Test.bat"
    5.     Dim destination As String = fileP & "\Test Folder\Test.bat"
    6.     FileCopy(source, destination)
    7.  
    8.     MessageBox.Show(String.Format("'{0}' File Copied to '{1}'", source, destination))
    9. End Sub
    Thank you so much, your a life saver, ill add you to the credits <3, thanks alot.. <3

    you to jmcilhinney , quick reply to, Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width