How to tell if its a file or a directory

This is a discussion on How to tell if its a file or a directory within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm using WinInet to connect to an FTP server and have sort of like a File -> Open type ...

  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,796
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 01:44 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21