Exclude extension

[b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
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;


Comments

  • : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : 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.
  • : : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : : 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.
    :

  • : : : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : : : 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 .

  • : : : : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : : : : 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 .
    :
    :
    [code]
    FileExt := ExtractFileExt(Filename);
    Filename := StringReplace(Filename, FileExt, '', []);
    // Other stuff
    NewFilename := NewFilename + FileExt;
    [/code]
  • [b][red]This message was edited by Tim3000 at 2005-7-15 6:28:27[/red][/b][hr]
    : : : : : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : : : : : 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 .
    : :
    : :
    : [code]
    : FileExt := ExtractFileExt(Filename);
    : Filename := StringReplace(Filename, FileExt, '', []);
    : // Other stuff
    : NewFilename := NewFilename + FileExt;
    : [/code]
    :

    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.


  • : [b][red]This message was edited by Tim3000 at 2005-7-15 6:28:27[/red][/b][hr]
    : : : : : : [b][red]This message was edited by Tim3000 at 2005-7-15 0:21:40[/red][/b][hr]
    : : : : : : 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 .
    : : :
    : : :
    : : [code]
    : : FileExt := ExtractFileExt(Filename);
    : : Filename := StringReplace(Filename, FileExt, '', []);
    : : // Other stuff
    : : NewFilename := NewFilename + FileExt;
    : : [/code]
    : :
    :
    :
    :thanks for the help again but
    I now found the ultimate solution :)

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

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories