Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A question about addresses

  1. Nov 27, 2007 #1
    Hi all, I've had great time here with some very helpful answer. Thank you all.

    Now my question. I am making a program which takes input from a text file and does somethings with it. Now the directory that text file is on my computer is "C:\input.txt".

    but sometimes I want to transport my program and the input.txt file using a thumbdrive or simply transfer it to another computer. When I do I notice the address which I assign the file to be in my C# program (eg.Filestream( @"C:\input.txt", .... , .....) ) is set to C:\.. and since the text file is not there in another computer I am using, my program does not execute.

    Is there a way to write the address so that it changes as I move my text file or have the program find the needed text file without it having it to be the "exact" directory?

  2. jcsd
  3. Nov 27, 2007 #2
    The easiest thing to do here is to say not "C:\input.txt", but just "input.txt". If you say just "input.txt" it will look for input.txt in "the current folder".

    If you want to be super fancy, there is this trick in .NET where you can actually embed a file "into" your program, so that it is hidden inside of the .exe or whatever, and you can always be guaranteed you will be able to find it. I have never actually used it myself but I think this feature is called "embedded resources" and some information on this seems to show up if you google for
    ".net assembly embedded resource"
  4. Dec 7, 2007 #3


    User Avatar
    Science Advisor

    But resource files are usually compressed in a .resx file or in an assembly and can't easily be manipulated outside of the app, so it's not the best option for acquiring input data.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook