473,396 Members | 1,734 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.

Problem with System.IO.Path.Combine()

308 256MB
HI,
I am getting problem while combining the path "c:" and "File1.txt".The .Net's
Path.Combine('c:","File1.txt") merely returns c:File1.txt hence Path.combine(string path) always retuen false , though file exists in the drive.Can anybody tell me what may b the remeady over this?
Thanks!
Sep 1 '08 #1
6 8594
joedeene
583 512MB
HI,
I am getting problem while combining the path "c:" and "File1.txt".The .Net's
Path.Combine('c:","File1.txt") merely returns c:File1.txt hence Path.combine(string path) always retuen false , though file exists in the drive.Can anybody tell me what may b the remeady over this?
Thanks!
perhaps adding a forward slash after 'c:' so your code should look like

Expand|Select|Wrap|Line Numbers
  1. System.IO.Path.Combine("C:\", "File1.txt")
right ?

joedeene
Sep 1 '08 #2
madankarmukta
308 256MB
perhaps adding a forward slash after 'c:' so your code should look like

Expand|Select|Wrap|Line Numbers
  1. System.IO.Path.Combine("C:\", "File1.txt")
right ?

joedeene
Hi,
Thanks for the quick update.But How can i make it more generic..? What if in the function Path.combine(path1,path2) we are having path1 as "c:\\temp1\\" and path2 as "text.txt" then in this can concatinating the path1 with "\" won't
b the solution..?

Thanks!
Sep 1 '08 #3
vekipeki
229 Expert 100+
Look for these methods:

Expand|Select|Wrap|Line Numbers
  1. String.EndsWith (String) 
  2. String.StartsWith (String)
in your .Net documentation, and use them to check whether your string ends or begins with "\\".
Sep 1 '08 #4
It only misbehaves when you feed root directory without slash as first argument. Always has as long as I've used it. So does:
Expand|Select|Wrap|Line Numbers
  1. DirectoryInfo dir = new DirectoryInfo("C:")
But both of these will work:
Expand|Select|Wrap|Line Numbers
  1. Path.Combine(@"C:\Some Dir", "File.txt");
  2. Path.Combine(@"C:\Some Dir\", @"File.txt");
I've always assumed it's because C: is not a valid place on the disk, the root starts at C:\ so to speak.
Sep 1 '08 #5
Plater
7,872 Expert 4TB
In the days of DOS and multiple drives, if the "current directory" on C drive was c:\temp\ and you were currently sitting in A:\install\, refering to JUST "c:" would dump you in "c:\temp\" whereas "c:\" would be just that, "c:\".
That was just the way microsoft/dos handled it's mounting system.
If you really look they're all like \{root}\bus[0]\device[0]\hda or something like that in XP.
Sep 2 '08 #6
madankarmukta
308 256MB
In the days of DOS and multiple drives, if the "current directory" on C drive was c:\temp\ and you were currently sitting in A:\install\, refering to JUST "c:" would dump you in "c:\temp\" whereas "c:\" would be just that, "c:\".
That was just the way microsoft/dos handled it's mounting system.
If you really look they're all like \{root}\bus[0]\device[0]\hda or something like that in XP.

Ohh..

Thanks everybody for much response..
I solved the problem just by concatenating path1 with "\" .Rest is taken care of by path.combine..

Thanks!
Sep 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: gry | last post by:
I want to write some kind of install script for my python app that will add c:\cygwin\usr\bin to the system path. I don't want to walk around to 50 PC's and twiddle through the GUI to: My...
3
by: andrea_gavana | last post by:
Hello NG, I have a GUI (written in wxPython) that calls some external exe files.. Some of them requires that I add to the PATH variable 1 directory. Basically, the exe are located in: ...
1
by: darrel | last post by:
We've purchased a component that requires us to install two DLLs. One we add as a reference to our project, but the otherone we have to add to the 'environment setup' as a system path reference....
7
by: thisis | last post by:
Hi All, myGetImage.asp is suppose to create a temporary file in the client side, and display in on the client web browser. myGetImage.asp needs to know the clients web browser temporary...
0
by: Rory Parore | last post by:
The documentation says that Path.IsPathRooted(path) returns true if path is an absolute directory, otherwise false. However, if I pass in "C:" it returns true, but this is treated as a relative...
0
by: Seemaraj | last post by:
hi to all I would like to store one of my file in windows system 32 folder while executing the application .Later i hav to check whether that file exists in the system path the next i execute it.....
3
by: Seemaraj | last post by:
Hi to all I would like to store one of my file in windows system 32 folder while installing my application.Later ,when i execute my application i need check whether that particular file exist or...
3
by: redefined.horizons | last post by:
I have been trying to find a way to add a directory to Python's sytem path on my MS Windows XP computer. I did some searching online, but the only solution I found involved editing the MS Windows...
0
by: drken567 | last post by:
I'm trying to execute a command line from my C++ .NET code/WinXP. The program (call it myprog.exe) is located in a directory (C:\mypath) which is included in the system 'path' environment variable....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.