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!!!!
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
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.
Re: Set Directory VB .net 2022
Quote:
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?
Re: Set Directory VB .net 2022
Quote:
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.
Re: Set Directory VB .net 2022
His code is in a form where mine isn't. Why is that?
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.
Re: Set Directory VB .net 2022
Quote:
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.
Re: Set Directory VB .net 2022
Tried that also, still not moving to the correct drive
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.