SHFileOperation - create folder silently

Posted on 2007-09-28
Last Modified: 2008-01-09
I am using SHFileOperation to move a file.
If the destination folder exists it works fine.
If the destination folder does not exist then it should be created WITHOUT the user confirming.

Using these flags: FOF_NOCONFIRMATION | FOF_SILENT  | FOF_NOERRORUI then it WON'T create the folder.
Using these flags: FOF_NOCONFIRMATION | FOF_SILENT  the I always get the confirmation dialog.

So, what flags do I require for it to create a folder silently?
Question by:AndyAinscow
    LVL 12

    Expert Comment

    Create the destination folder on your own via
    BOOL MakeSureDirectoryPathExists(
      PCSTR DirPath

    The MakeSureDirectoryPathExists function creates all the directories in the specified DirPath, beginning with the root.

    LVL 43

    Author Comment

    Isn't there any set of flags to make the SHFileOperation perform the action silently?  

    As I said it will create the directory, it just requests confirmation even when specifying silent operation unless I use the FOF_NOERRORUI and then it fails to create the folder.
    LVL 43

    Author Comment

    ps. For UNICODE (my case) I would need the SHCreateDirectoryEx function not the MakeSureDirectoryPathExists function
    LVL 5

    Expert Comment

    I dont know about SHFileOperation ...

    But you can achive the same with useing CreateDirectory API.
          WIN32_FIND_DATA oFindFileData ;
          ZeroMemory(&oFindFileData, sizeof(WIN32_FIND_DATA) );
          HANDLE hRet = FindFirstFile(_T("d:\\t2\\*.*"), &oFindFileData );
          if (hRet == INVALID_HANDLE_VALUE)
                CreateDirectory(_T("d:\\t2"), NULL);
                hRet = (HANDLE) 0 ;
    LVL 43

    Author Comment

    Thanks - but to create the folder then the SHCreateDirectoryEx function works perfectly well.

    I would like to know what flags one could use with the SHFileOperation to do it silently as part of a move operation.
    LVL 12

    Accepted Solution


    Copy and Move operations can specify destination directories that do not exist and the system will attempt to create them. The system normally displays a dialog box to ask the user if they want to create the new directory. To suppress this dialog box and have the directories created silently, set the FOF_NOCONFIRMMKDIR flag in fFlags.
    LVL 43

    Author Comment

    Excellent - now why didn't I see it in the help file.  (Don't answer).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now