Page 1 of 1
How do you detect if item is a file or folder.
Posted: Mon Dec 05, 2011 8:20 pm
by Happyrever
In the simple process of drag and drop of files into a field, the result is a text string showing the full path and file name.
However, the same result applies if a folder is drag & dropped. This is expected.
However, I need some way of excluding the case where it is a folder being D&D.
Example:-
C:/Users/Alan/Documents/Serial Numbers/Alans drivers/U-values
U-values is a folder and not a file and must be excluded.
I would expect the point to detect the folder rather than file is at the point of starting to drag the item, but cannot think how to detect this.
Any ideas or code?
Re: How do you detect if item is a file or folder.
Posted: Mon Dec 05, 2011 8:44 pm
by Klaus
Hi Happy,
unfoertunately you cannot prevent this from being dragged to your app!
I usually "postprocess" the dropped files after the user dropped them like this:
Code: Select all
...
put the dragdata["files"] into tFiles
## This does ALSO contain dropped folders!
repeat for each line i in tFiles:
## We don't need no stinking badg... erm. folders here :-)
if there is folder i then
next repeat
end if
put i & CR after tRealFiles
end repeat
delete char -1 of tRealFiles
...
Now tRealFiles only contains files
Best
Klaus
Re: How do you detect if item is a file or folder.
Posted: Mon Dec 05, 2011 9:00 pm
by mwieder
Well, you can *sort of* do this by trapping it in dragEnter:
Code: Select all
on dragEnter
if there is a folder the dragData["files"] then
set the dragAction to "none"
else
set the dragAction to "copy"
end if
end dragEnter
see an example at
http://lessons.runrev.com/s/lessons/m/4 ... -on-Fields
If you can't be sure that the user is dragging only one file/folder at a time then you have to parse through the dragData["files"] one line a a time, eliminating the ones that are folders. It's a bit messy.
Re: How do you detect if item is a file or folder.
Posted: Mon Dec 05, 2011 9:34 pm
by Happyrever
Thank you both for your advice.
I had tried the Drag version mwieder suggested, but it did not work. I put that down to me rather than the suggestion. However, it is expected the buser will drag afolder full of files, so that knocks it on the head anyway.
The post processing is fine for me and I can slip that in without any disruption to my code. I am sure this will work and will try it tomorrow.
Thanks Klaus