• 7 odgovora
  • 3.641 pregleda
Kako resiti da se ekstenzija ne prikazuje? 14.11.2004. u 12:19 · pre 267 meseci #1
Koristim:
Edit: TEdit
DriveComboBox1: TDriveComboBox
DirectoryListBox: TDirectoryListBox
Brojfajlova: TLabel
grid: TStringGrid
Directory: TDirectoryListBox
FileListBox: TFileListBox
Code:

procedure TForm1.Button1Click(Sender: TObject);
var
   rootDir:string;
procedure bros(const root:string);
var
   i,j,dirIterate:word;
   subdirs:TstringList;
     a,b:string;
begin
   subdirs:=Tstringlist.Create;
   Directory.Directory:=root;
   Directory.OpenCurrent;
a:=floattostr(j);
   if FileListBox.items.count>0 then
      for j:=0 to FileListBox.items.count-1 do
         begin
         grid.cells[0,grid.RowCount-1]:=fileListBox.Items[j];
         grid.cells[1,grid.RowCount-1]:=root;

         grid.cells[2,grid.RowCount-1]:=NazivFajla(a);
         grid.RowCount:=grid.RowCount+1;
         end;
  if not(Directory.ItemIndex=Directory.Items.Count-1) then
      begin
      for i:=Directory.ItemIndex+1 to Directory.Items.count-1 do
         begin
         if Directory.itemindex=0 then
             subdirs.add(Directory.Directory+Directory.Items[i]) 
           else
             subdirs.add(Directory.Directory+'\'+Directory.Items[i]);
         end;

      for dirIterate:=0 to subdirs.Count-1 do
         bros(subdirs[dirIterate]);
      end;
   subdirs.Free;
end;
begin
FileListBox.Mask:='*.'+Edit.text;
grid.RowCount:=2;
grid.Cells[0,1]:='';
grid.Cells[1,1]:='';
grid.Cells[0,0]:='Naziv fajla';
grid.Cells[1,0]:='Lokacija';
screen.Cursor:=-11;
bros(DirectoryListBox.Directory);
if grid.RowCount > 2 then
   grid.RowCount:=grid.RowCount-1;
if grid.cells[0,1]<>'' then
   Brojfajlova.Caption:='Ukupan broj pronadjenih fajlova: '+inttostr(grid.rowcount-1)
else
   Brojfajlova.Caption:='Ukupan broj pronadjenih fajlova: 0';
screen.Cursor:=0;
end;

Ovaj gore navedeni kod koristim i sve lepo ferca. All... Program u prvoj koloni prikazuje naziv fajla, a u drugoj lokaciju. Samo zelim da ne prikazuje ekstenziju fajla.

Npr u prvoj koloni
Anastacia - Left Outside Alone.mp3.....da bude.....Anastacia - Left Outside Alone
Blacke Eyed Peas - Shut Up.mp3.........da bude.....Blacke Eyed Peas - Shut Up
znaci da nema *.mp3

Da li neko zna kako da ovo resim?
Unapred hvala!!!
Potpis
GYGY
Re: Kako resiti da se ekstenzija ne prikazuje? 14.11.2004. u 13:29 · pre 267 meseci #2
Recimo da ti se ime fajla sa extenzijom nalazi u promenljivoj ime_fajla :

Code:

var
  ime_bez_ext : String;
begin
  ime_bez_ext := Copy(ime_fajla, 1, Length(ime_fajla) - 4);
end;

Ovaj kod u stvari uzima string cija je duzina za 4 karaktera manja od imena fajla.

Mozes i sa Delete() funkcijom.
Re: Kako resiti da se ekstenzija ne prikazuje? 14.11.2004. u 21:22 · pre 267 meseci #5
Ovo ferca ali ako je ekstenzija sa 3 slova:
Code:
...
procedure TForm1.Button1Click(Sender: TObject);
var
  ime_fajla : String;
   rootDir:string;
procedure browsesub(const root:string);
var
   i,j,dirIterate:word;
   subdirs:TstringList;
begin
   subdirs:=Tstringlist.Create;
   Directory.Directory:=root;
   Directory.OpenCurrent;
   if FileListBox.items.count>0 then
      for j:=0 to FileListBox.items.count-1 do
         begin
         ime_fajla:=fileListBox.Items[j];
         grid.cells[0,grid.RowCount-1]:=Copy(ime_fajla, 1, Length(ime_fajla) - 4);
...

A ovo nece da moze:
Code:
...
procedure TForm1.Button1Click(Sender: TObject);
var
  s: String;
   rootDir:string;
procedure browsesub(const root:string);
var
   i,j,dirIterate:word;
   subdirs:TstringList;
begin
   subdirs:=Tstringlist.Create;
   Directory.Directory:=root;
   Directory.OpenCurrent;
   if FileListBox.items.count>0 then
      for j:=0 to FileListBox.items.count-1 do
         begin
         s:=fileListBox.Items[j];
         grid.cells[0,grid.RowCount-1]:=Delete(s, Length(s) - Length(ExtractFileExt(s)) + 1, Length(ExtractFileExt(s)) );
...

sta je neispravno?
hvala!
Potpis
GYGY
Re: Kako resiti da se ekstenzija ne prikazuje? 14.11.2004. u 21:51 · pre 267 meseci #6
Ovo:

Code:

         s:=fileListBox.Items[j];
         grid.cells[0,grid.RowCount-1]:=Delete(s, Length(s) ...


zameni sa:

Code:

         s:=fileListBox.Items[j];
         Delete(s, Length(s) - Length(ExtractFileExt(s)) + 1, Length(ExtractFileExt(s)));
         grid.cells[0,grid.RowCount-1]:= s;



Ovo je samo ako imas problem sa brisanjem extenzije, ostatak kooda nisam gledao...

ss.
Potpis
When something is hard to do, then it's not worth doing.
Re: Kako resiti da se ekstenzija ne prikazuje? 15.11.2004. u 10:00 · pre 267 meseci #7
Sta je bre ovo :), takmicenje za najteze resenje? Probaj ovo:


Code:

novoime:= ChangeFileExt(fileListBox.Items[j],ExtractFileExt(fileListBox.Items[j]));
Re: Kako resiti da se ekstenzija ne prikazuje? 15.11.2004. u 10:10 · pre 267 meseci #8
Na brzinu sam iscupao is Help-a, neke od funkcija za manipulaciju imenom datoteke.
Da ne trosite vreme na parsiranje :)


ChangeFileExt function
Changes the extension of a file name.

ExpandFileName function
Returns the full path name for a relative file name.

ExtractFileDir function
Extracts the drive and directory parts from FileName.

ExtractFileDrive function
Returns the drive portion of a file name.

ExtractFileExt function
Returns the extension portions of a file name.

ExtractFileName function
Extracts the name and extension parts of a file name.

ExtractFilePath function
Returns the drive and directory portions of a file name.

ExtractRelativePath function
Returns a relative path name, relative to a specific base directory.
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme