Solved

splitting a filename into its components

Posted on 1999-01-10
2
171 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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