Difference between files and folders?

This is a discussion on Difference between files and folders? within the C Programming forums, part of the General Programming Boards category; Can someone please tell me what is the difference between files and folder as far as when I am using ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    27

    Difference between files and folders?

    Can someone please tell me what is the difference between files and folder as far as when I am using findfirst and findnext?

    If I'm trying to see if my the current folder contains a subfolder, do I just do something like this?

    int i;
    struct ffblk FileBlock
    // Let's say path is something like D:\tmp
    i = findfirst (Path, &FileBlock, FA_DIREC);

    Is this only going to return 0 if there is a subfolder?

    And if I do this instead?

    i = findfirst (Path, &FileBlock, (FA_NORMAL | FA_RDONLY));

    This should find only the normal files and read-only files?

    Thank you.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Can someone please tell me what is the difference between files and folder as far as when I am using findfirst and findnext?
    First of all my version of VC++ does not have the dir.h header file. So, I really couldn't test this code snippet. The FA_DIREC means include directories and files. So, you'll have to check each ffblk found against the FA_DIREC atttribute to identify a directory.

    Code:
    int main (void)
      {
        struct ffblk fb;
        int finished;
        finished = _findfirst ("*.*", &fb, FA_DIREC);
        while (!finished)
        {
          if (fb.ff_attrib & FA_DIREC)
            printf ("%s\n", fb.ff_name);
          finished = _findnext (&fb);
        }
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    27
    How about opening or closing a folder? Like you do fopen to open a file right? Is that apply to folders too? Or do i just specify the folder as part of a path then look for files in there?

    Also, somewhat unrelated to the topic, but do I delete a file with remove()? When I read the doocumentation, it says that what remove does is unlink a file so that it's no longer accessible. So I'm not sure if that means something similar to remove a pointer to memory, in which case I'll get memory leaks? Or does it actually remove the file from the hard drive? Can I do remove on a folder too?

    Thanks.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    > do I delete a file with remove()?
    Creating a simple test program will give you the answer. Remove does have less of a visible effect if you did not call fclose on the file stream first, though.

    > Can I do remove on a folder too?
    Probably not. For security reasons the OS probably won't let your program create or delete folders with some simple file I/O. Look into some API stuff, or something.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,167
    Quote Originally Posted by fanoliv
    How about opening or closing a folder? Like you do fopen to open a file right? Is that apply to folders too? Or do i just specify the folder as part of a path then look for files in there?
    You don't need to "open" a folder. Just specify it in the path.

    Quote Originally Posted by fanoliv
    Can I do remove on a folder too?
    Learning how to use documentation would be a great first step for you. Try the *NIX manual pages for a start: http://www.hmug.org/man/3/remove.php

    What you find there is the following excerpt:
    SYNOPSIS
    #include <stdio.h>

    int remove(const char *path);



    DESCRIPTION
    The remove() function removes the file or directory specified by path.

    If path specifies a directory, remove(path) is the equivalent of
    rmdir(path)
    . Otherwise, it is the equivalent of unlink(path).
    So we simply look up the rmdir() function the same way. You find the following excerpt there:
    SYNOPSIS
    #include <unistd.h>

    int rmdir(const char *path);



    DESCRIPTION
    Rmdir() removes a directory file whose name is given by path. The direc-
    tory must not have any entries other than `.' and `..'.
    And there you have your answer with 30 seconds of research. remove() can remove a directory as long as the directory is empty.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. geting full path of files and folders (boost::filesystem)
    By umen242 in forum C++ Programming
    Replies: 2
    Last Post: 05-18-2008, 11:37 PM
  2. List files in a directory (without folders)
    By 3saul in forum Linux Programming
    Replies: 4
    Last Post: 04-20-2006, 01:08 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. comparing files and folders
    By vivek_kumbhar in forum C Programming
    Replies: 2
    Last Post: 01-03-2003, 10:30 AM
  5. Folders and text files
    By tim545666 in forum C++ Programming
    Replies: 11
    Last Post: 02-17-2002, 03:15 PM

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