Delete files and subfolder using c programing (Urgent

This is a discussion on Delete files and subfolder using c programing (Urgent within the C Programming forums, part of the General Programming Boards category; Hi, I am new to C programing. I want a program like , if i given folder path . IT ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    5

    Delete files and subfolder using c programing (Urgent

    Hi,

    I am new to C programing.

    I want a program like , if i given folder path . IT has to delete the all the subfolder and files.

    Please help me on this.

    Regards,
    Raaj

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Why would you want this, and what work have you already done on such a program?

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    5
    Hi ,

    I dont knw C . So how can i prepare. Any way i want to genarate one exe file. By running that exe iwant to delete the files and folders.

    Please help meon this OR give a code for that program.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Oh, so you want me to teach you C or do your work for you? I don't think so.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    5
    ok , do the program for me

  6. #6
    Banned
    Join Date
    May 2008
    Location
    Four Dots Planet
    Posts
    72
    If you really do not know C then why do you need to write such program? Which OS are you using?

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    5
    i am using windows xp . my team lead requirement.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by telukuntla View Post
    i am using windows xp . my team lead requirement.
    Why would you want to do that? There's already a built-in command in cmd.exe (command prompt) in Windows.
    Code:
    del foldername /s
    If the purpose is for you to "learn how you do this", then you should perhaps LEARN something, rather than ask someone else who already know how to do this how to do it.

    I would suggest that you look at "how to find files and folders" (not quite sure of the exact name, but it should be fairly obvious) in the FAQ.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by telukuntla View Post
    ok , do the program for me
    If you can't figure this out, you probably should not be working as a programmer.

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    5
    can you tell me one thing .

    # include <windows.h>

    what it is and how can i include this file into my code

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by telukuntla View Post
    can you tell me one thing .

    # include <windows.h>

    what it is and how can i include this file into my code
    To use it, you tut that line in the beginning (not necessarily the first) lines of your .c file.

    When you ask "What it is", that's much harder to answer, because you may be asking:
    "What does windows.h contain?" - to which the short answer is "Lot of definitions of functions, types and structures that are part of the Windows API". For more details, you need some book or such on the Windows API.

    "How does it affect my program?" - it enables you to make use of Windows API functions.

    Or many other questions, including ones that I couldn't even imagine...


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    I really don't see much point in creating this program in C, anyway you are probably not using the best language for it (esp since it is a completely new language and isn't quick to learn, and the program could be more easily developed as a batch script (see Batch files - Ask for user input. If you still want to program it in C, you might want to include:
    Code:
    include <stdio.h>
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    I see the next comment from your team lead being "where the hell are all my files!?"

    Some notes on the use of the word "urgent" when asking for help.
    http://www.catb.org/~esr/faqs/smart-...ns.html#urgent
    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.

  14. #14
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    #pragma comment( lib, "shell32.lib" )
    
    #include <stdio.h>
    #include <windows.h>
    #include <shellapi.h>
    
    BOOL DeleteDirectory(char *pSource)
    {
    	SHFILEOPSTRUCT sh;
    	ZeroMemory(&sh, sizeof(SHFILEOPSTRUCT));
    	sh.hwnd = NULL;
    	sh.wFunc = FO_DELETE;
    	sh.pFrom = pSource;
    	sh.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
    	return !SHFileOperation( &sh );
    }
    
    int main(void)
    {
    	if(DeleteDirectory("C:\\TEMP") == FALSE)
    		printf("Temp folderNOT deleted\n");
    	else   printf("Temp folder deleted Successfully\n");
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

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