Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHFileOperation - problem using FOF_NOCONFIRMMKDIR

Status
Not open for further replies.

ardentdev

Programmer
Oct 30, 2002
7
0
0
US
I'm having trouble using SHFileOperation to move files between two directories. The problem occurs when the source folder contains a subfolder that is not found in the destination folder. I would like the application to create the subfolder in the destination folder without confirmation from the user. The code works fine if I remove the flags and click OK to confirm the creation of the directory but does not work when I try to do the same without user confirmation.

The code is below. Does anyone see where my problem is? Note that the code runs without generating errors, it just does not create the new subfolder or transfer files in that folder.

-----------------------------
*** code from declarations ***

Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString _
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title
End Type

Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
' Available Operations
Const FO_COPY As Long = &H2 ' Copy File/Folder
Const FO_DELETE As Long = &H3 ' Delete File/Folder
Const FO_MOVE As Long = &H1 ' Move File/Folder
Const FO_RENAME As Long = &H4 ' Rename File/Folder
' Flags
Const FOF_ALLOWUNDO As Long = &H40 ' Allow to undo rename, delete ie sends to recycle bin
Const FOF_FILESONLY As Long = &H80 ' Only allow files
Const FOF_NOCONFIRMATION As Long = &H10 ' No File Delete or Overwrite Confirmation Dialog
Const FOF_NOCONFIRMMKDIR As Long = &H200 ' No make directory confirmation dialog
Const FOF_SILENT As Long = &H4 ' No copy/move dialog
Const FOF_SIMPLEPROGRESS As Long = &H100 ' Does not display file names

----------------------------------------
*** code snippet from sub ***

Dim op As SHFILEOPSTRUCT

With op
.wFunc = FO_MOVE
.pTo = msProductionDirectory & sNewFileName
.pFrom = objFile.Path
.fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR Or FOF_SILENT
End With
SHFileOperation op

TIA!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top