All files look like directories

  • Thread starter Thread starter jennifereden.price
  • Start date Start date
J

jennifereden.price

Hi,

I have the following function in a project that implements a shell
extension. This function shows all the files that the users has
selected and attempts to determine whether it is a directory or a file.
But, for some reason, it thinks that every file is a directory! I don't
understand the system aspect of the code - I only understand what it
formally does. Can anyone help me spot my error? Many thanks in
advance! Aaron Fude

public static void ShowSelected(uint m_hDrop) {
// if ( (uFlags & (uint)CMF.CMF_DEFAULTONLY) != 0) return;
uint nselected = DllImports.DragQueryFile(m_hDrop, 0xffffffff, null,
0);
for (uint s = 0; s < nselected; s++) {
StringBuilder sb = new StringBuilder(1024);
DllImports.DragQueryFile(m_hDrop, s, sb, sb.Capacity + 1);
string file = sb.ToString();
uint attr = DllImports.GetFileAttributes(file);

bool isdir = (attr & DllImports.FILE_ATTRIBUTE_DIRECTORY) != 0;
MessageBox.Show(((isdir)?"Directory: ":"File: ") + file + " " + attr
+ " " + isdir);

}
 
Can anyone help me spot my error?

Not without seeing your API declarations, especially the one for
GetFileAttributes.

Instead of calling GetFileAttributes, you could consider using
System.IO.File.GetAttributes.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top