list files without extension

I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
thanks a lot

Comments

  • : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : thanks a lot
    :
    You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
  • : : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : : thanks a lot
    : :
    : You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
    :



    this is my code can you see whats wrong ?



    Function TForm1.FileLook(Filespec:string; Node : TTreeNode):boolean;
    var
    TempNode : TTreeNode;
    validres:integer;
    SearchRec : TSearchRec;
    DirPath, FullName, Flname : string;
    begin

    DirPath:=ExtractFilePath(FileSpec);
    Result:= DirectoryExists(DirPath);
    If not Result then exit;
    Flname:=ExtractFileName(FileSpec);
    validres := FindFirst(FileSpec, faAnyFile, SearchRec);
    while validres=0 do begin
    If (SearchRec.Name[1] <> '.') then begin {not a dotted directory}
    FullName:=DirPath + LowerCase(SearchRec.Name);
    FileExtensions := TStringList.Create;
    {add folder/file as child of current Node}




    sExt := ExtractFileExt(Searchrec.Name);


    // Kopieer uit SearchResult.Name alles behalve de sExt
    sFile := Copy(Searchrec.name, 0, Length(Searchrec.name) - Length(sExt));



    TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);
    If (SearchRec.Attr and faDirectory>0) then begin{is a folder}
    TempNode.ImageIndex := ISAClosedFolder;
    TempNode.SelectedIndex := ISAOpenFolder;
    FileLook(FullName+''+Flname, TempNode);
    end
    else {not a folder must be a file, get its icon}
    FindFilesIcon(FullName, TempNode);
    end;
    validres:=FindNext(SearchRec); {continue scanning current
    folder for files and other folders}
    end;
    end;




  • : : : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : : : thanks a lot
    : : :
    : : You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
    : :
    :
    :
    :
    : this is my code can you see whats wrong ?
    :
    :
    :
    : Function TForm1.FileLook(Filespec:string; Node : TTreeNode):boolean;
    : var
    : TempNode : TTreeNode;
    : validres:integer;
    : SearchRec : TSearchRec;
    : DirPath, FullName, Flname : string;
    : begin
    :
    : DirPath:=ExtractFilePath(FileSpec);
    : Result:= DirectoryExists(DirPath);
    : If not Result then exit;
    : Flname:=ExtractFileName(FileSpec);
    : validres := FindFirst(FileSpec, faAnyFile, SearchRec);
    : while validres=0 do begin
    : If (SearchRec.Name[1] <> '.') then begin {not a dotted directory}
    : FullName:=DirPath + LowerCase(SearchRec.Name);
    : FileExtensions := TStringList.Create;
    : {add folder/file as child of current Node}
    :
    :
    :
    :
    : sExt := ExtractFileExt(Searchrec.Name);
    :
    :
    : // Kopieer uit SearchResult.Name alles behalve de sExt
    : sFile := Copy(Searchrec.name, 0, Length(Searchrec.name) - Length(sExt));
    :
    :
    :
    : [red]TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);[/red]
    : If (SearchRec.Attr and faDirectory>0) then begin{is a folder}
    : TempNode.ImageIndex := ISAClosedFolder;
    : TempNode.SelectedIndex := ISAOpenFolder;
    : FileLook(FullName+''+Flname, TempNode);
    : end
    : else {not a folder must be a file, get its icon}
    : FindFilesIcon(FullName, TempNode);
    : end;
    : validres:=FindNext(SearchRec); {continue scanning current
    : folder for files and other folders}
    : end;
    : end;
    :
    :
    :
    :
    :
    A string isn't zero-indexed, but 1 indexed. This means that Copy(String, 0, SomeLength) should be Copy(String, [red]1[/red], SomeLength). Also you don't give the node's name the changed filename, but the original one (as indicated above).
  • : : : : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : : : : thanks a lot
    : : : :
    : : : You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
    : : :
    : :
    : :
    : :
    : : this is my code can you see whats wrong ?
    : :
    : :
    : :
    : : Function TForm1.FileLook(Filespec:string; Node : TTreeNode):boolean;
    : : var
    : : TempNode : TTreeNode;
    : : validres:integer;
    : : SearchRec : TSearchRec;
    : : DirPath, FullName, Flname : string;
    : : begin
    : :
    : : DirPath:=ExtractFilePath(FileSpec);
    : : Result:= DirectoryExists(DirPath);
    : : If not Result then exit;
    : : Flname:=ExtractFileName(FileSpec);
    : : validres := FindFirst(FileSpec, faAnyFile, SearchRec);
    : : while validres=0 do begin
    : : If (SearchRec.Name[1] <> '.') then begin {not a dotted directory}
    : : FullName:=DirPath + LowerCase(SearchRec.Name);
    : : FileExtensions := TStringList.Create;
    : : {add folder/file as child of current Node}
    : :
    : :
    : :
    : :
    : : sExt := ExtractFileExt(Searchrec.Name);
    : :
    : :
    : : // Kopieer uit SearchResult.Name alles behalve de sExt
    : : sFile := Copy(Searchrec.name, 1, Length(Searchrec.name) - Length(sExt));
    : :
    : :
    : :
    : : [red]TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);[/red]
    : : If (SearchRec.Attr and faDirectory>0) then begin{is a folder}
    : : TempNode.ImageIndex := ISAClosedFolder;
    : : TempNode.SelectedIndex := ISAOpenFolder;
    : : FileLook(FullName+''+Flname, TempNode);
    : : end
    : : else {not a folder must be a file, get its icon}
    : : FindFilesIcon(FullName, TempNode);
    : : end;
    : : validres:=FindNext(SearchRec); {continue scanning current
    : : folder for files and other folders}
    : : end;
    : : end;
    : :
    : :
    : :
    : :
    : :
    : A string isn't zero-indexed, but 1 indexed. This means that Copy(String, 0, SomeLength) should be Copy(String, [red]1[/red], SomeLength). Also you don't give the node's name the changed filename, but the original one (as indicated above).
    :
    ok thanks i have changed the zero to 1
    sorry but this don't realy understand what do i need to do here do I need to add this - Length(sExt ??

    TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);

  • : : : : : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : : : : : thanks a lot
    : : : : :
    : : : : You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
    : : : :
    : : :
    : : :
    : : :
    : : : this is my code can you see whats wrong ?
    : : :
    : : :
    : : :
    : : : Function TForm1.FileLook(Filespec:string; Node : TTreeNode):boolean;
    : : : var
    : : : TempNode : TTreeNode;
    : : : validres:integer;
    : : : SearchRec : TSearchRec;
    : : : DirPath, FullName, Flname : string;
    : : : begin
    : : :
    : : : DirPath:=ExtractFilePath(FileSpec);
    : : : Result:= DirectoryExists(DirPath);
    : : : If not Result then exit;
    : : : Flname:=ExtractFileName(FileSpec);
    : : : validres := FindFirst(FileSpec, faAnyFile, SearchRec);
    : : : while validres=0 do begin
    : : : If (SearchRec.Name[1] <> '.') then begin {not a dotted directory}
    : : : FullName:=DirPath + LowerCase(SearchRec.Name);
    : : : FileExtensions := TStringList.Create;
    : : : {add folder/file as child of current Node}
    : : :
    : : :
    : : :
    : : :
    : : : sExt := ExtractFileExt(Searchrec.Name);
    : : :
    : : :
    : : : // Kopieer uit SearchResult.Name alles behalve de sExt
    : : : [blue]sFile := Copy(Searchrec.name, 1, Length(Searchrec.name) - Length(sExt));[/blue]
    : : :
    : : :
    : : :
    : : : [red]TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);[/red]
    : : : If (SearchRec.Attr and faDirectory>0) then begin{is a folder}
    : : : TempNode.ImageIndex := ISAClosedFolder;
    : : : TempNode.SelectedIndex := ISAOpenFolder;
    : : : FileLook(FullName+''+Flname, TempNode);
    : : : end
    : : : else {not a folder must be a file, get its icon}
    : : : FindFilesIcon(FullName, TempNode);
    : : : end;
    : : : validres:=FindNext(SearchRec); {continue scanning current
    : : : folder for files and other folders}
    : : : end;
    : : : end;
    : : :
    : : :
    : : :
    : : :
    : : :
    : : A string isn't zero-indexed, but 1 indexed. This means that Copy(String, 0, SomeLength) should be Copy(String, [red]1[/red], SomeLength). Also you don't give the node's name the changed filename, but the original one (as indicated above).
    : :
    : ok thanks i have changed the zero to 1
    : sorry but this don't realy understand what do i need to do here do I need to add this - Length(sExt ??
    :
    : TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);
    :
    :
    In the blue line you assign the filename without extention to the variable sFile. In the red line you then set the SearchRec.Name as the Node's caption. Since you didn't change the value of the SearchRec.Name variable, you still set the filename with extension as the Node's caption. Also you nowhere use the variable sFile in the rest of your code.
  • : : : : : : I have listed files in a treeview but it also list the file extension any body know how i can change that.? it should only list the filenames . extension must be invissible
    : : : : : : thanks a lot
    : : : : : :
    : : : : : You can get the extension by using the ExtractFileExt() function. Then a Copy() or Delete() together with a Pos() can be used to remove it.
    : : : : :
    : : : :
    : : : :
    : : : :
    : : : : this is my code can you see whats wrong ?
    : : : :
    : : : :
    : : : :
    : : : : Function TForm1.FileLook(Filespec:string; Node : TTreeNode):boolean;
    : : : : var
    : : : : TempNode : TTreeNode;
    : : : : validres:integer;
    : : : : SearchRec : TSearchRec;
    : : : : DirPath, FullName, Flname : string;
    : : : : begin
    : : : :
    : : : : DirPath:=ExtractFilePath(FileSpec);
    : : : : Result:= DirectoryExists(DirPath);
    : : : : If not Result then exit;
    : : : : Flname:=ExtractFileName(FileSpec);
    : : : : validres := FindFirst(FileSpec, faAnyFile, SearchRec);
    : : : : while validres=0 do begin
    : : : : If (SearchRec.Name[1] <> '.') then begin {not a dotted directory}
    : : : : FullName:=DirPath + LowerCase(SearchRec.Name);
    : : : : FileExtensions := TStringList.Create;
    : : : : {add folder/file as child of current Node}
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : sExt := ExtractFileExt(Searchrec.Name);
    : : : :
    : : : :
    : : : : // Kopieer uit SearchResult.Name alles behalve de sExt
    : : : : [blue]sFile := Copy(Searchrec.name, 1, Length(Searchrec.name) - Length(sExt));[/blue]
    : : : :
    : : : :
    : : : :
    : : : : [red]TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);[/red]
    : : : : If (SearchRec.Attr and faDirectory>0) then begin{is a folder}
    : : : : TempNode.ImageIndex := ISAClosedFolder;
    : : : : TempNode.SelectedIndex := ISAOpenFolder;
    : : : : FileLook(FullName+''+Flname, TempNode);
    : : : : end
    : : : : else {not a folder must be a file, get its icon}
    : : : : FindFilesIcon(FullName, TempNode);
    : : : : end;
    : : : : validres:=FindNext(SearchRec); {continue scanning current
    : : : : folder for files and other folders}
    : : : : end;
    : : : : end;
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : A string isn't zero-indexed, but 1 indexed. This means that Copy(String, 0, SomeLength) should be Copy(String, [red]1[/red], SomeLength). Also you don't give the node's name the changed filename, but the original one (as indicated above).
    : : :
    : : ok thanks i have changed the zero to 1
    : : sorry but this don't realy understand what do i need to do here do I need to add this - Length(sExt ??
    : :
    : : TempNode := TreeView1.Items.AddChild(Node, SearchRec.Name);
    : :
    : :
    : In the blue line you assign the filename without extention to the variable sFile. In the red line you then set the SearchRec.Name as the Node's caption. Since you didn't change the value of the SearchRec.Name variable, you still set the filename with extension as the Node's caption. Also you nowhere use the variable sFile in the rest of your code.
    :

    Thanks a lot! i understand now :)
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