1

I'm using someone else's code (licensed) on two different machines. On one machine, the Application.ExecutablePath returns the result the programmer must have expected, on the other it does not. Both are Windows 7 machines.

On my machine, the Application.ExecutablePath returns something like:

"C:\\Dir1\\Dir2\\Dir3/bin/Debug/APP.EXE"

On the other machine, it returns

"C:\\Dir1\\Dir2\\Dir3\\bin/Debug/APP.EXE"

The programmer obviously expected the second return string, because the code does this:

  string path = Application.ExecutablePath;
  short found = (short)path.LastIndexOf(@"\");

  if (found > -1)
  {
    path = path.Substring(0, found);
  }
  try
  {
    foreach (string File in Directory.GetFiles(path + @"\Res\Patterns\", "*.xml"))
    {
      found = (short)File.LastIndexOf(@"\");
      if (found > -1)
        //... use files found

and the directory of files is present in both machines under Dir3, so it is found on the other machine but not on mine. I can't find any information on when and where Windows decides to return the forward slash (like a URL path) vs. the UNC path using "\". Why would this code work differently on different machines?

1 Answer 1

1

I am guessing that the path you simplified to C:\\Dir1\\Dir2\\Dir3/bin/debug actually had a hash (#) in the Dir3 name.

This is a quirk with Application.ExecutablePath apparently. You can use Assembly.GetEntryAssembly().Location instead, which returns consistent results.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.