current working directory problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    #1

    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.

  • I Don't Like Spam

    #2
    Re: current working directory problem

    Jeff wrote:[color=blue]
    > 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.
    >[/color]

    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")

    Comment

    • Jeff

      #3
      Re: current working directory problem

      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.

      Comment

      • CMM

        #4
        Re: current working directory problem

        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" <jeffmagill@gma il.com> wrote in message
        news:1139087291 .246965.282600@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > 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.
        >[/color]


        Comment

        • Prabhakar Kasi

          #5
          Re: current working directory problem

          Hi pal,
          I was breaking my head to get the current working directroy..Than ks a lot.....
          ---
          Posted via www.DotNetSlackers.com

          Comment

          Working...