Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Exclude extension Posted by Tim3000 on 15 Jul 2005 at 12:18 AM
This message was edited by Tim3000 at 2005-7-15 0:21:40

If you search for files how can you exclude the extensions from the filenames?

with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
anybody any idea ? Thanks a lot!

if FindFirst('*.*', faAnyFile, searchResult) = 0 then

begin

repeat
Found := Found + 1;
stringlist := TStringList.Create;
Memo1.Lines.Add(searchresult.name);

RenameFile(SearchResult.Name ,
StringReplace(SearchResult.Name, 'DA', 'D3',
[rfReplaceAll, rfIgnoreCase] ))


until FindNext(searchResult) <> 0;
FindClose(searchResult);
StringList.Free;

end;


Report
Re: Exclude extension Posted by zibadian on 15 Jul 2005 at 12:54 AM
: This message was edited by Tim3000 at 2005-7-15 0:21:40

: If you search for files how can you exclude the extensions from the filenames?
:
: with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: anybody any idea ? Thanks a lot!
:
: if FindFirst('*.*', faAnyFile, searchResult) = 0 then
:
: begin
:
: repeat
: Found := Found + 1;
: stringlist := TStringList.Create;
: Memo1.Lines.Add(searchresult.name);
:
: RenameFile(SearchResult.Name ,
: StringReplace(SearchResult.Name, 'DA', 'D3',
: [rfReplaceAll, rfIgnoreCase] ))
:
:
: until FindNext(searchResult) <> 0;
: FindClose(searchResult);
: StringList.Free;
:
: end;
:
:
:
You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
Report
Re: Exclude extension Posted by Tim3000 on 15 Jul 2005 at 1:47 AM
: : This message was edited by Tim3000 at 2005-7-15 0:21:40

: : If you search for files how can you exclude the extensions from the filenames?
: :
: : with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: : anybody any idea ? Thanks a lot!
: :
: : if FindFirst('*.*', faAnyFile, searchResult) = 0 then
: :
: : begin
: :
: : repeat
: : Found := Found + 1;
: : stringlist := TStringList.Create;
: : Memo1.Lines.Add(searchresult.name);
: :
: : RenameFile(SearchResult.Name ,
: : StringReplace(SearchResult.Name, 'DA', 'D3',
: : [rfReplaceAll, rfIgnoreCase] ))
: :
: :
: : until FindNext(searchResult) <> 0;
: : FindClose(searchResult);
: : StringList.Free;
: :
: : end;
: :
: :
: :
: You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
:

Report
Re: Exclude extension Posted by Tim3000 on 15 Jul 2005 at 1:48 AM
: : : This message was edited by Tim3000 at 2005-7-15 0:21:40

: : : If you search for files how can you exclude the extensions from the filenames?
: : :
: : : with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: : : anybody any idea ? Thanks a lot!
: : :
: : : if FindFirst('*.*', faAnyFile, searchResult) = 0 then
: : :
: : : begin
: : :
: : : repeat
: : : Found := Found + 1;
: : : stringlist := TStringList.Create;
: : : Memo1.Lines.Add(searchresult.name);
: : :
: : : RenameFile(SearchResult.Name ,
: : : StringReplace(SearchResult.Name, 'DA', 'D3',
: : : [rfReplaceAll, rfIgnoreCase] ))
: : :
: : :
: : : until FindNext(searchResult) <> 0;
: : : FindClose(searchResult);
: : : StringList.Free;
: : :
: : : end;
: : :
: : :
: : :
: : You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
: :
:
:Thanks but would be great if you can give an example .

Report
Re: Exclude extension Posted by zibadian on 15 Jul 2005 at 4:45 AM
: : : : This message was edited by Tim3000 at 2005-7-15 0:21:40

: : : : If you search for files how can you exclude the extensions from the filenames?
: : : :
: : : : with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: : : : anybody any idea ? Thanks a lot!
: : : :
: : : : if FindFirst('*.*', faAnyFile, searchResult) = 0 then
: : : :
: : : : begin
: : : :
: : : : repeat
: : : : Found := Found + 1;
: : : : stringlist := TStringList.Create;
: : : : Memo1.Lines.Add(searchresult.name);
: : : :
: : : : RenameFile(SearchResult.Name ,
: : : : StringReplace(SearchResult.Name, 'DA', 'D3',
: : : : [rfReplaceAll, rfIgnoreCase] ))
: : : :
: : : :
: : : : until FindNext(searchResult) <> 0;
: : : : FindClose(searchResult);
: : : : StringList.Free;
: : : :
: : : : end;
: : : :
: : : :
: : : :
: : : You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
: : :
: :
: :Thanks but would be great if you can give an example .
:
:
  FileExt := ExtractFileExt(Filename);
  Filename := StringReplace(Filename, FileExt, '', []);
  // Other stuff
  NewFilename := NewFilename + FileExt;

Report
Re: Exclude extension Posted by Tim3000 on 15 Jul 2005 at 6:27 AM
This message was edited by Tim3000 at 2005-7-15 6:28:27

: : : : : This message was edited by Tim3000 at 2005-7-15 0:21:40

: : : : : If you search for files how can you exclude the extensions from the filenames?
: : : : :
: : : : : with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: : : : : anybody any idea ? Thanks a lot!
: : : : :
: : : : : if FindFirst('*.*', faAnyFile, searchResult) = 0 then
: : : : :
: : : : : begin
: : : : :
: : : : : repeat
: : : : : Found := Found + 1;
: : : : : stringlist := TStringList.Create;
: : : : : Memo1.Lines.Add(searchresult.name);
: : : : :
: : : : : RenameFile(SearchResult.Name ,
: : : : : StringReplace(SearchResult.Name, 'DA', 'D3',
: : : : : [rfReplaceAll, rfIgnoreCase] ))
: : : : :
: : : : :
: : : : : until FindNext(searchResult) <> 0;
: : : : : FindClose(searchResult);
: : : : : StringList.Free;
: : : : :
: : : : : end;
: : : : :
: : : : :
: : : : :
: : : : You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
: : : :
: : :
: : :Thanks but would be great if you can give an example .
: :
: :
:
:   FileExt := ExtractFileExt(Filename);
:   Filename := StringReplace(Filename, FileExt, '', []);
:   // Other stuff
:   NewFilename := NewFilename + FileExt;
: 

:

Thanks,but I am actualy searching for an different method cause this can't work in my case.
I am searching for an method so that I can exclude the last 4 characters in the renaming procces ,so the last 4 characters of an filenames or multiple files ,he must leave that alone . last 4 characters . t x t so then my code would leave extension alone in the renaming procces .do you have any idea how I can do this ? theire must be an way I only have to find it :) would be great if you know how to do this.


Report
Re: Exclude extension Posted by Tim3000 on 15 Jul 2005 at 7:21 AM
: This message was edited by Tim3000 at 2005-7-15 6:28:27

: : : : : : This message was edited by Tim3000 at 2005-7-15 0:21:40

: : : : : : If you search for files how can you exclude the extensions from the filenames?
: : : : : :
: : : : : : with this I get the filenames from current dir so thats fine but I don't want the Extension of the filenames cause then with renaming characters I run into problems ...or is it possible to exclude the last 4 characters of the filenames in the renaming procces ? (so it leaves the Extension unchanged)
: : : : : : anybody any idea ? Thanks a lot!
: : : : : :
: : : : : : if FindFirst('*.*', faAnyFile, searchResult) = 0 then
: : : : : :
: : : : : : begin
: : : : : :
: : : : : : repeat
: : : : : : Found := Found + 1;
: : : : : : stringlist := TStringList.Create;
: : : : : : Memo1.Lines.Add(searchresult.name);
: : : : : :
: : : : : : RenameFile(SearchResult.Name ,
: : : : : : StringReplace(SearchResult.Name, 'DA', 'D3',
: : : : : : [rfReplaceAll, rfIgnoreCase] ))
: : : : : :
: : : : : :
: : : : : : until FindNext(searchResult) <> 0;
: : : : : : FindClose(searchResult);
: : : : : : StringList.Free;
: : : : : :
: : : : : : end;
: : : : : :
: : : : : :
: : : : : :
: : : : : You can get the externsion with ExtractFileExt(). Once you have that stored separately, you can remove it from the filename. Then rename the file and append the extensoin back to it.
: : : : :
: : : :
: : : :Thanks but would be great if you can give an example .
: : :
: : :
: :
: :   FileExt := ExtractFileExt(Filename);
: :   Filename := StringReplace(Filename, FileExt, '', []);
: :   // Other stuff
: :   NewFilename := NewFilename + FileExt;
: : 

: :
:
:
:thanks for the help again but
I now found the ultimate solution :)

sFile := Copy(SearchResult.Name, 1, Length(SearchResult.Name) - Length(sExt));




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.