-
Nov 8th, 2022, 03:48 PM
#1
Thread Starter
Junior Member
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.
-
Nov 8th, 2022, 04:17 PM
#2
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
-
Nov 9th, 2022, 08:58 AM
#3
Thread Starter
Junior Member
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
-
Nov 9th, 2022, 09:44 AM
#4
Re: Set Directory VB .net 2022
Originally Posted by Darby
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?
-
Nov 9th, 2022, 12:00 PM
#5
Re: Set Directory VB .net 2022
Originally Posted by Darby
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.
-
Dec 7th, 2022, 03:47 PM
#6
Thread Starter
Junior Member
Re: Set Directory VB .net 2022
His code is in a form where mine isn't. Why is that?
-
Dec 7th, 2022, 03:54 PM
#7
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.
-
Dec 7th, 2022, 06:26 PM
#8
Re: Set Directory VB .net 2022
Originally Posted by Darby
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.
-
Dec 27th, 2022, 04:03 PM
#9
Thread Starter
Junior Member
Re: Set Directory VB .net 2022
Tried that also, still not moving to the correct drive
-
Dec 27th, 2022, 04:08 PM
#10
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|