current working directory problem

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I feel like I should have been able to figure this out but I can't seem
to find any references on this topic.

It seems like my current working directory is consistently a few
directories up from where I am storing the file - not what I would have
expected. I would have expected it to be the same directory as the dir
with my code - I guess I was wrong because thats not what is happening.

On my own computer it wasn't a big problem because I dodged the
problem by put my data in the root wherever that may have been.
However, now that I have uploaded my files to the internet, I don't
have that kind of control of my file system and I don't know the
structure to make an absolute work path.

Dim oRead as System.IO.StreamReader
Dim oFile as System.IO.File
oRead = oFile.OpenText("Library.txt")

the code is simple enough. is there anyway to resolve this? perhaps by
setting the current working directory or some other solution? it seems
that sticking my data files in the same directory as the app isn't
enough. the fact that my directory hierarchy is unpredictable is
complicating things beyond my ability. thanks in advance.

as i am writing this the idea ccured to me that maybe I should just
find out the directory hierarchy from my host.
 
Jeff said:
I feel like I should have been able to figure this out but I can't seem
to find any references on this topic.

It seems like my current working directory is consistently a few
directories up from where I am storing the file - not what I would have
expected. I would have expected it to be the same directory as the dir
with my code - I guess I was wrong because thats not what is happening.

On my own computer it wasn't a big problem because I dodged the
problem by put my data in the root wherever that may have been.
However, now that I have uploaded my files to the internet, I don't
have that kind of control of my file system and I don't know the
structure to make an absolute work path.

Dim oRead as System.IO.StreamReader
Dim oFile as System.IO.File
oRead = oFile.OpenText("Library.txt")

the code is simple enough. is there anyway to resolve this? perhaps by
setting the current working directory or some other solution? it seems
that sticking my data files in the same directory as the app isn't
enough. the fact that my directory hierarchy is unpredictable is
complicating things beyond my ability. thanks in advance.

as i am writing this the idea ccured to me that maybe I should just
find out the directory hierarchy from my host.

If you can put the file in the same directory as the app then do:


Dim oRead as System.IO.StreamReader
Dim oFile as System.IO.File
oRead = oFile.OpenText(Application.StartupPath & "\Library.txt")
 
The file is in the same directory as the app however it seems that the
current working directory is completely somewhere else. My probelm is
compounded because the start up path is arbitrary.
 
This is a misunderstanding that has been around forever. Yes, your "working
directory" can seem to be arbitrary. It is set by the OS when your program
starts and is determined either by the shortcut that starts your program
(right click on a shortcut and check the "Start In" field), where the
program is started from (Windows Explorer, command prompt, spawned from some
other program and this inheriting that other programs working dir, etc), and
other stuff.

"I don't like Spam's" answer should solve your problem.
 
Hi pal,
I was breaking my head to get the current working directroy..Thanks a lot.....
 
Back
Top