Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Drag & Drop, is it File or Folder

Posted on 2005-04-30
3
Medium Priority
?
240 Views
Last Modified: 2010-04-05
hi, I have this code below..

  private
  procedure DropFiles(var Msg: TMessage); message WM_DropFiles;
..
  implementation
..
procedure TForm1.DropFiles(var Msg: TMessage);
var
  i, amount, size: Integer;
  Filename: PChar;
  S: string;
begin
  inherited;
  Amount := DragQueryFile(Msg.WParam,$FFFFFFFF,Filename,255);
  for i := 0 to (Amount-1) do begin
    size := DragQueryFile(Msg.WParam,i,nil,0) + 1;
    Filename:= StrAlloc(size);
    DragQueryFile(Msg.WParam,i,Filename,size);
    s := ExtractFileExt(Filename);

    listbox1.Items.Add(StrPas(Filename)+' '+s);

    StrDispose(Filename);
  end;
  DragFinish(Msg.WParam);
end;
..
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(listbox1.Handle,True);
end;

I'd like to know if its a file or folder that is being dragged into the listbox.

using if bla = bla then begin, something like that so I have 2 options.

could anyone provide an example?

Sal.
0
Comment
Question by:SaLz
3 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 1600 total points
ID: 13901913
I might use the dephi

DirectoryExists( )

function


maybe

if DirectoryExists(FileName) then
  DoFolderCode else
  DoFileCode;
0
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 400 total points
ID: 13901971
I would do a FindFirst, then use the attribute to find out if is a directory

you can use this function:

function IsDirectory(const TheFile:string):Boolean;
var
  S:TSearchRec;
begin
  Result:=True;
  if (FindFirst(TheFile, faAnyFile, S)=0) then
  begin
    Result:=(S.Attr and faDirectory)>0;
    FindClose(S)
  end
end;

  if (IsDirectory('c:\winnt')) then
    ShowMessage('is directory')
0
 
LVL 2

Author Comment

by:SaLz
ID: 13902050
thxs :D
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question