[script] Removing the path from a string
Anyone knows how I can remove the path from a filename string with a script ?
There's a lot of functions to manipulate strings in the script reference, but I can't figure out wich would allow me to extract a substring.
There's a lot of functions to manipulate strings in the script reference, but I can't figure out wich would allow me to extract a substring.
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
I've found. It could'nt be simpler.
extractFileName(pString);
http://www.delphibasics.co.uk/RTL.asp?N ... ctFileName
extractFileName(pString);
http://www.delphibasics.co.uk/RTL.asp?N ... ctFileName
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
Hi guys,
I find this post very interesting, but I'm not familiar with scripts and I don't know how to use this information.
I tried to copy this in an empty script but I had a couple of errors. If someone can help me.
Thanks
Kenan
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
interface
uses
SysUtils, // Unit containing the ExtractFileName command
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
fullFileName : string;
begin
// Set up a full file name with drive and path
fullFileName := 'C:Program FilesBorlandDelphi7ProjectsUnit1.dcu';
// Show the component parts of this full name
ShowMessage('Drive = '+ExtractFileDrive (fullFileName));
ShowMessage('Dir = '+ExtractFileDir (fullFileName));
ShowMessage('Path = '+ExtractFilePath (fullFileName));
ShowMessage('Name = '+ExtractFileName (fullFileName));
ShowMessage('Ext = '+ExtractFileExt (fullFileName));
end;
end.
I find this post very interesting, but I'm not familiar with scripts and I don't know how to use this information.
I tried to copy this in an empty script but I had a couple of errors. If someone can help me.
Thanks
Kenan
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
interface
uses
SysUtils, // Unit containing the ExtractFileName command
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
fullFileName : string;
begin
// Set up a full file name with drive and path
fullFileName := 'C:Program FilesBorlandDelphi7ProjectsUnit1.dcu';
// Show the component parts of this full name
ShowMessage('Drive = '+ExtractFileDrive (fullFileName));
ShowMessage('Dir = '+ExtractFileDir (fullFileName));
ShowMessage('Path = '+ExtractFilePath (fullFileName));
ShowMessage('Name = '+ExtractFileName (fullFileName));
ShowMessage('Ext = '+ExtractFileExt (fullFileName));
end;
end.
Hi, I suppose you found a Deplhi example somewhere? Usine is written (mostly?) in Delphi, and you can use quite a lot of the functions and procedures from Delphi within scripts, but far from all. I haven't really programmed in Delphi myself, but I'm pretty sure that the above example creates a simple window of sorts and displays the various parts of the pathfile string.
Here's an example script for Usine accepting one input - the pathfile name - and displays the extracted strings in the console every time the script is initiated or the file name input changes:
Paste it into an empty script module and compile. You can connect an Interface Control/Open Dialog module to input if you want, but you can also just enter text strings to see how the different extracts.
Here's an example script for Usine accepting one input - the pathfile name - and displays the extracted strings in the console every time the script is initiated or the file name input changes:
Code: Select all
VAR pFileName : tParameter;
PROCEDURE Init;
BEGIN
pFileName := CreateParam('pathFile name', ptTextField); SetIsOutput(pFileName, FALSE);
END;
PROCEDURE Callback(n: Integer);
VAR fileName : String;
BEGIN
fileName := GetStringValue(pFileName);
WriteLn('Input file name = ' + fileName);
WriteLn('Drive = ' + ExtractFileDrive(fileName));
WriteLn('Dir = ' + ExtractFileDir(fileName));
WriteLn('Path = ' + ExtractFilePath(fileName));
WriteLn('Name = ' + ExtractFileName(fileName));
WriteLn('Ext = ' + ExtractFileExt(fileName));
END;Bjørn S
Hi,
Thanks for your answer. Unfortunately it doesn't work as expected. The whole string is getting out of the script. I'll have to search in my archives books about Turbo Pascal and relearn this language...

Thanks
Thanks for your answer. Unfortunately it doesn't work as expected. The whole string is getting out of the script. I'll have to search in my archives books about Turbo Pascal and relearn this language...

Thanks
If what you're after is the "stripped" file name as an output from the script, you have to create an output for it and assign a value to the output. WriteLn (along with sTrace, iTrace and fTrace) just writes to the console for showing messages, debugging etc.
Create another parameter, eg pFileNameOut. This should also be of type ptTextField. In Callback, you can do something like:
Create another parameter, eg pFileNameOut. This should also be of type ptTextField. In Callback, you can do something like:
Code: Select all
PROCEDURE Callback(n : Integer);
BEGIN
IF (n = pFileName) THEN
SetStringValue(pFileNameOut, ExtractFileName(GetStringValue(pFileName)));
END;Bjørn S
Hi,
It works perfectly now, thank you very much...
Kenan
It works perfectly now, thank you very much...
Kenan
Who is online
Users browsing this forum: No registered users and 24 guests
