Solved

splitting a filename into its components

Posted on 1999-01-10
2
170 Views
Last Modified: 2010-04-06
Hi experts,

suppose we have a file:

filename:='c:\programs\windows\my file.txt';

how can I split this filename into its components?

drive:='c:';
directory:='\programs\windows\';
name:='my file';
extension:='.txt';


With kind regards

Mathes
0
Comment
Question by:mathes
  • 2
2 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 10 total points
ID: 1355708
Hi Mathes,

drive:=ExtractFileDrive(filename);
directory:=ExtractFilePath(filename);
Delete(directory,1,length(drive));
name:=ExtractFileName(filename);
extension:=ExtractFileExt(filename);
Delete(name,length(name)+1-length(extension),maxInt);

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1355709
Hmm. Normally it's this way:

drive:='c:\';
directory:='programs\windows\';

If you want to have it the other way round, add this line after the "drive:=..." line:

Delete(drive,length(drive),1);
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question