Results 1 to 10 of 10

Thread: Set Directory VB .net 2022

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    16

    Set Directory VB .net 2022

    I need to be sure that a project is set to the correct drive and directory before a sub program continues to run.

    I've used GetCurrentDirectory() to see if I am already there and then SetCurrentDirectory() to change it if not.

    Code:
    If(Directory.GetCurrentDirectory() <> "J:" Then
    Directory.SetCurrentDirectory("J:")
    End if
    That Didn't work, I also tried Just

    Code:
    Directory.SetCurrentDirectory(J:")
    to just set the directory in case it wasn't already set.
    Also didn't work.

    I've been programming for over 50 years, at least the past 10-12 in Visual Basic, one version or another, and I cannot remember how to do this (79 years old, the mind is not as sharp). No matter where I look, I cannot find the answer. PLEASE HELP!!!!
    Last edited by Darby; Dec 27th, 2022 at 04:05 PM.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Set Directory VB .net 2022

    Untested, but it might just be as simple as including the trailing backslash:

    Code:
    If Directory.GetCurrentDirectory() <> "J:\" Then
        Directory.SetCurrentDirectory("J:\")
    End if

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    16

    Re: Set Directory VB .net 2022

    actual code does have backslashes but for some reason when I typed it in here it dropped them. I tried to correct it but still dropped them. But I did try it without the backslash also.
    Last edited by Darby; Nov 9th, 2022 at 09:04 AM. Reason: won't show backslash

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

    Re: Set Directory VB .net 2022

    Quote Originally Posted by Darby View Post
    for some reason when I typed it in here it dropped them
    Do you notice anything different about the way you posted your code to the way OptionBase1 posted their code?

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Set Directory VB .net 2022

    Quote Originally Posted by Darby View Post
    I need to be sure that a project is set to the correct drive and directory before a sub program continues to run....
    If you know the correct drive and directory just set it, skip checking.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    16

    Re: Set Directory VB .net 2022

    His code is in a form where mine isn't. Why is that?

  7. #7
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Set Directory VB .net 2022

    If you enclose the code in Code tags (the # button on the Reply header symbols line), the text will not get edited.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Set Directory VB .net 2022

    Quote Originally Posted by Darby View Post
    His code is in a form where mine isn't. Why is that?
    You could have just hit 'Reply With Quote' on that post and seen for yourself.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    16

    Re: Set Directory VB .net 2022

    Tried that also, still not moving to the correct drive

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    16

    Re: Set Directory VB .net 2022

    If you read the complete post, you will see that I did try just setting the directory without checking.

Tags for this Thread

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