473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

current working directory problem

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.

Feb 4 '06 #1
4 3667
Jeff wrote:
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")
Feb 4 '06 #2
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.

Feb 4 '06 #3
CMM
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.

"Jeff" <je********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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.

Feb 4 '06 #4
Hi pal,
I was breaking my head to get the current working directroy..Thanks a lot.....
---
Posted via www.DotNetSlackers.com
Feb 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shaun Heveron | last post by:
Hi, I'm working on a portable ANSI C++ application designed to compile and execute under Windows and LINUX/UNIX. Is there a portable way of obtaining the current working directory? Sorry, if...
2
by: ssjassal | last post by:
Is there a way to instruct Python to import modules from standard library even if there is one with the same name in the current working directory? I was trying to import BaseHTTPServer.py from...
0
by: dgk | last post by:
Is there a FAQ somewhere about how to publish a web app to a (2003) server? I've mapped a drive to a directory under inetpub/wwwroot, and used the Visual Studio "Publish Web Site" menu option to...
3
by: Chris Mellon | last post by:
This appears to be a change in behavior from Python 2.4 to Python 2.5, which I can't find documented anywhere. It may be windows only, or related to Windows behavior. In 2.4, the current...
6
by: Bina | last post by:
Hi, I m new in c#.net . In C#.net, how i will get the current working path? when i used following function "Application.StartupPath" then it show the executable...
14
by: gio | last post by:
I have a problem and the solution should works under windows and unix OS. Suppose I have a program ex.c in the directory X (so the current working directory of ex.c is X). Also suppose I have...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
2
by: Tim Kelley | last post by:
I have a project that includes images as part of the project. I have a grid (Infragistics) with a button that the user clicks and it brings up a file open dialog that is used to browse to a file...
2
by: Kakkanattu | last post by:
Hi, In desktop application, we use different ways to get the current execution directory. I. AppDomain.CurrentDomain.BaseDirectory II. Environment.CurrentDirectory...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.