# Visual Basic > Visual Basic .NET >  Set Directory VB .net 2022

## Darby

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. 



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

That Didn't work, I also tried Just



```
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!!!!

----------


## OptionBase1

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



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

----------


## Darby

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.

----------


## jmcilhinney

> 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?

----------


## dbasnett

> 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.

----------


## Darby

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

----------


## jdc2000

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

----------


## jmcilhinney

> 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.

----------


## Darby

Tried that also, still not moving to the correct drive

----------


## Darby

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

----------

