Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


SHFileOperation - create folder silently

Posted on 2007-09-28
Medium Priority
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
  • 4
  • 2
LVL 12

Expert Comment

ID: 19977505
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 45

Author Comment

ID: 19977636
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 45

Author Comment

ID: 19977645
ps. For UNICODE (my case) I would need the SHCreateDirectoryEx function not the MakeSureDirectoryPathExists function
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 19977947
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 45

Author Comment

ID: 19978009
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

OnegaZhang earned 2000 total points
ID: 19978467

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 45

Author Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

569 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