473,774 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Strea mReader
Dim oFile as System.IO.File
oRead = oFile.OpenText( "Library.tx t")

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 3684
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.Strea mReader
Dim oFile as System.IO.File
oRead = oFile.OpenText( "Library.tx t")

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.Strea mReader
Dim oFile as System.IO.File
oRead = oFile.OpenText( Application.Sta rtupPath & "\Library.t xt")
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 misunderstandin g 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********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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..Than ks 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
5401
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 I'm being stupid... Thanks,
2
1575
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 standard library but was prevented by a python file with the same name in current working directory (but there was no __init__.py). Can I use some warning switch to print a warning on stdout? Thanks, Sunpreet.
0
3517
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 build and publish it. The app files show up on the server. I went into IIS and created it the app as a virtual directory. Now IIS looks good, with the gear icon on the directory, but trying to access the application via IE gives this message: ...
3
3190
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 directory (os.curdir) was on sys.path. In 2.5, it appears to be the base directory of the running script. For example, if you execute the file testme.py in your current working directory, '' is on sys.path. If you execute c:\Python25\Scripts\testme.py,...
6
99679
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 path.(e:\Project\DataList\bin\debug). But i have created my project at the project directory. Now i want to get the path (e:\Project\DataList\). How i will get this? IS there any solution to solve this problem? I have created my crystal report file in the "e:\Project\DataList\"...
14
13561
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 this code fragment: .... char otherpath; char cmd;
3
8243
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 will change the current working directory to the directory which include the script, so my script cannot find the data file. I think this is the problem of emacs because when I start pdb from console directly, it will not change current...
2
2426
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 so the path can be saved in the grid. After the dialog is closed the program cannot find any of the images that are part of the project. I believe that using the open file dialog is changing the working directory and causing the error. Is there...
2
2627
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 III. Directory.GetCurrentDirectory() IV. Assembly.GetExecutingAssembly().Location Can u please help me to know the difference of all these? Also is there any other way to get the current directory other than the above?
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10040
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.