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

x
?
Solved

SHFileOperation - create folder silently

Posted on 2007-09-28
7
Medium Priority
?
986 Views
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?
0
Comment
Question by:AndyAinscow
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:OnegaZhang
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.

0
 
LVL 45

Author Comment

by:AndyAinscow
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.
0
 
LVL 45

Author Comment

by:AndyAinscow
ID: 19977645
ps. For UNICODE (my case) I would need the SHCreateDirectoryEx function not the MakeSureDirectoryPathExists function
0
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.

 
LVL 5

Expert Comment

by:abith
ID: 19977947
I dont know about SHFileOperation ...

But you can achive the same with useing CreateDirectory API.
eg:
      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 ;
      }
0
 
LVL 45

Author Comment

by:AndyAinscow
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.
0
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 2000 total points
ID: 19978467
FOF_NOCONFIRMMKDIR

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.
0
 
LVL 45

Author Comment

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

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