473,398 Members | 2,403 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,398 software developers and data experts.

Complete path name?

Hello,

I use an initialized "System.IO.FileInfo" class. The properties
"myFileInfo.FullName" or "myFileInfo.DirectoryName" deliver the directory
with MS-DOS convention.
Example: "c:\docume~1\...".

How can i get the full Path.
Example: "c:\documents\..."

Thanks in advance,
Hubert
Nov 15 '05 #1
1 1949
Using only built-in functionality, you cant. The problem is that whenever
you call the DirectoryName (or any System.IO.FileInfo or
System.IO.DirectoryInfo Name or FullName property) you get the name exactly
as you spelled it while calling the property. FileInfo and DirectoryInfo
never check whether actual file or directory exist while calling
DirectoryName (or Name or FullName) properties, they simply read it from
string you specified while creating the FileInfo or DirectoryInfo instances.

In order to get the correct full name you have to write your own method
which could look like this one:

private string DirectoryFullName(System.IO.DirectoryInfo dir)
{
string dirName = "";
while (dir.Parent != null)
{
string thisDir = dir.GetDirectories(".")[0].Name;
dirName = thisDir + (dirName != "" ? "\\" : "") + dirName;
dir = dir.Parent;
}
return dir.Root + dirName;
}

The trick is to call GetDirectories specifying the current directory (.) as
search pattern. The DirectoryInfo array you get will contain the list of
actual directories as they exist in the filesystem. Repeating the process as
long as there are parent directories will give you exactly the result you
need.

Regards,

--
Vjekoslav Babic, MCSA, MCDBA

"Hubert Hermanutz" <hh********@kavo.de> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
Hello,

I use an initialized "System.IO.FileInfo" class. The properties
"myFileInfo.FullName" or "myFileInfo.DirectoryName" deliver the directory
with MS-DOS convention.
Example: "c:\docume~1\...".

How can i get the full Path.
Example: "c:\documents\..."

Thanks in advance,
Hubert

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kenneth McDonald | last post by:
I have a need to customize the output of Python error tracebacks, and to that end I've implemented my own sys.excepthook function. However, one remaining problem that I'm having is the information...
9
by: Bengt dePaulis | last post by:
I have a local directory that I want to include in my sys.path How to save it permanently? Regards /Bengt
3
by: Cactus | last post by:
Hi, I have a tree like structure build with javascrtip and loads of iframes. How can find the complete 'frame-path' to the frame that focused? I'm sure I can contruct something with hidden input...
34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
4
by: Gérard Leclercq | last post by:
Can't find exemple. How can i delete a complete folder including subfolders and files in the subfolders. Or do i to delete one by one ? Gérard.
12
by: Anders Eriksson | last post by:
Hello! I'm trying to create a program that will watch a directory and when a file is created print that file. I have used FileSystemWatcher for watching the directory and I get an created event....
3
by: Rahul Agarwal | last post by:
Hi In our web page we use a combination of HTML and server side controls and some of them have a custom attribute based on which we need to find and replace the values once the HTML is ready. ...
0
by: SQACSharp | last post by:
Hi, I'm trying to get the complete path of all .exe returned by Process.GetProcesses() The problem is the "theprocess.MainModule.FileName"...sometime for some process it return stange...
1
by: indu19 | last post by:
Hi, I am still fresher in php. so i need help... How to get upload file's complete path and how to store it in DB move_uploaded_file($_FILES,"c:/Indu/".$_FILES); I upload file using...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
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
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.