Thread: How to tell if its a file or a directory

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    How to tell if its a file or a directory

    Hi,

    I'm using WinInet to connect to an FTP server and have sort of like a File -> Open type of application. Once it's connected, it reads in the list of folders in that directory, the user selects one and the program should open that one ad present all the folders in it. When I'm reading all the directories in, how do I check if it's a file or a directory? Because if it's a file I want to put it in a different list.

    Something like this:
    Code:
         BOOL bWorking = finder.FindFile(_T("*"));
    	
         while (bWorking)
        {
            bWorking = finder.FindNextFile();
    		fname = finder.GetFilePath();
    
    		if(a directory)
    			pListMain->AddString(fname);
    		else
    			pListSub->AddString(fname);        
    	}
    thanks.
    Everything is relative...

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I found this function, but I'm not sure if this is the proper method:
    Code:
                         if(strstr(fname,".txt"))
    			pListSub->AddString(fname);
    		else
    			pListMain->AddString(fname);
    Everything is relative...

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Try to open it as a directory. If that fails, it's a file.
    My best code is written with the delete key.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Read the manual and find out what other methods your 'finder' object supports.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM