Page 1 of 1
Posted: 07 Mar 2011, 01:29
by gthibert
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.
Posted: 07 Mar 2011, 03:10
by gthibert
I've found. It could'nt be simpler.
extractFileName(pString);
http://www.delphibasics.co.uk/RTL.asp?N ... ctFileName
Posted: 07 Mar 2011, 10:11
by 23fx23
cool, i wondered too.
Posted: 13 Mar 2011, 00:06
by Ken29
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.
Posted: 14 Mar 2011, 22:04
by bsork
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:
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;
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.
Posted: 20 Mar 2011, 10:38
by Ken29
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
Posted: 21 Mar 2011, 09:19
by bsork
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:
Code: Select all
PROCEDURE Callback(n : Integer);
BEGIN
IF (n = pFileName) THEN
SetStringValue(pFileNameOut, ExtractFileName(GetStringValue(pFileName)));
END;
Posted: 29 Mar 2011, 10:26
by Ken29
Hi,
It works perfectly now, thank you very much...
Kenan