Recent

Author Topic: (Solved)Fileutil  (Read 1496 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
(Solved)Fileutil
« on: November 24, 2020, 02:23:50 am »

Code: Pascal  [Select][+][-]
  1.  
  2.  Var AFile, ADir : String;
  3.       Item : String = 'C:\My Dir\MyFile.txt';
  4.  
  5.    AFile :=  ExtractFileNameWithoutExt( Item );  ===>    Returns  'C:\My Dir\MyFile
  6.  
  7.   ADir :=  ExtractShortPathNameUTF8( Item );  ===>    Returns 'C:\My Dir\MyFile.txt'  
  8.  
  9.  

i was think    ExtractFileNameWithoutExt would return 'MyFile' with out the path and
ExtractShortPathNameUTF8 would return 'My Dir'

 
« Last Edit: November 30, 2020, 02:10:26 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Fileutil
« Reply #1 on: November 24, 2020, 04:25:48 am »
Try something like this

Name := ExtraFileName(ExtraFileNameWithoutPath(TheName));
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Fileutil
« Reply #2 on: November 24, 2020, 05:44:43 am »
Thanks,

That would be equal to:

 Var AFileName : String = 'Nameofile.exe';
      Name : String

 begin
   Name := Copy2Symb( AFileName, '.' );
 end;

 Result := 'Nameoffile'



FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Fileutil
« Reply #3 on: November 24, 2020, 12:56:11 pm »
Didn't we have an ExtractFilenameOnly() function somewhere?

Bart

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: Fileutil
« Reply #4 on: November 24, 2020, 01:51:37 pm »
In LazFileUtils...
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Fileutil
« Reply #5 on: November 24, 2020, 09:38:52 pm »
@Bart You are right


There is a message in the message box saying:

 unit1.pas(1160,17) Warning: Symbol "ExtractFileNameWithoutExt" is deprecated: "

Use the function from unit LazFileUtils"

  function ExtractFileNameOnly(const AFilename : string) : string;

If it's Green I go I don't read those pesky messages, maybe I should.


FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Fileutil
« Reply #6 on: November 24, 2020, 10:14:29 pm »
If it's Green I go I don't read those pesky messages, maybe I should.

Yes, you should.
At some point the deprecated function will be removed, et voila, after you upgraded it won't compile anymore  O:-)

Bart

 

TinyPortal © 2005-2018