473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SHFileOpertion and FO_DELETE

Hello,

I am trying to delete a file using SHFileOperation, but get the error code
1026.

Code snippet:

SHFILEOPSTRUCT fo;
ZeroMemory(&fo, sizeof(fo));
fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
fo.wFunc = FO_DELETE; // delete contents of this folder
fo.pFrom = szFilename;
int nSuccessCode = SHFileOperation(&fo);

The file does exist and have tried with other files/paths etc but these do
not work.

Any ideas?
TIA
Simon Jefferies
Nov 16 '05 #1
2 5949
KC
There are a few reason why the operation failed. The file could be in use
and thus the deletion failed.

Another reason is, szFilename is not double NULL terminated. To ensure a
string is double NULL terminated you can initialize your buffer to NULL.

char szFileName[260];
memset(szFileName, 0, sizeof(szFileName));

strcpy(szFileName, "C:\\Hello");

Both member of SHFILEOPSTRUCT (pFrom and pTo) must be double NULL
terminated if they contain value.

Regards,
KC

"Simon Jefferies" <je*************@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP09.phx.gbl...
Hello,

I am trying to delete a file using SHFileOperation, but get the error code
1026.

Code snippet:

SHFILEOPSTRUCT fo;
ZeroMemory(&fo, sizeof(fo));
fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
fo.wFunc = FO_DELETE; // delete contents of this folder
fo.pFrom = szFilename;
int nSuccessCode = SHFileOperation(&fo);

The file does exist and have tried with other files/paths etc but these do
not work.

Any ideas?
TIA
Simon Jefferies

Nov 16 '05 #2
Hi Simon Jefferies
try this code it seems to work i tried this

SHFILEOPSTRUCT s ;
::ZeroMemory ( &s, sizeof ( s ) ) ; // Initialize the structure

CString f = "C:\\MyFolder" ;
//CString t = "D:\\" ;

char from [ MAX_PATH ], to [ MAX_PATH ] ; // buffer used to copy source and
target path

strcpy ( from, f ) ;
int l = f.GetLength( ) ;
from[l+1] = '\0' ;

//strcpy ( to, t ) ;
//l = t.GetLength( ) ;
//to[l+1] = '\0' ;

// Set the values in structure
s.hwnd = this -> m_hWnd ;
s.wFunc = FO_DELETE ;
s.pFrom = ( LPCTSTR ) from ;
//s.pTo = ( LPCTSTR ) to ;
s.fFlags = FOF_SIMPLEPROGRESS ;
s.lpszProgressTitle = "Moving files..." ;

::SHFileOperation ( &s ) ;

----
Deepak

"Simon Jefferies" <je*************@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP09.phx.gbl...
Hello,

I am trying to delete a file using SHFileOperation, but get the error code
1026.

Code snippet:

SHFILEOPSTRUCT fo;
ZeroMemory(&fo, sizeof(fo));
fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
fo.wFunc = FO_DELETE; // delete contents of this folder
fo.pFrom = szFilename;
int nSuccessCode = SHFileOperation(&fo);

The file does exist and have tried with other files/paths etc but these do
not work.

Any ideas?
TIA
Simon Jefferies

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3457
by: mt | last post by:
How can i use the "SHFileOperation" with vb.net. i use the below code; but i get the error " Object reference not set to an instance of an object" please advise (and can i use this api for...
12
39627
by: deko | last post by:
Is there a quick and dirty way to delete all files in a given directory? perhaps something like this: Set objFile = CreateObject("Scripting.FileSystemObject") objFile.DeleteFile "all files in...
8
9730
by: JezB | last post by:
In c# code how do I delete a file while ensuring it goes into the recycle bin for possible recovery ?
2
4254
by: Stefan | last post by:
Hi, I cannot get the code below to work (C#). I'm trying to send a file to the recycling bin, and I keep getting the following error: "Cannot delete file: Cannot read from the source file or...
1
1274
by: Dinesh Jain | last post by:
Hi all, File.Delete(fileName) causes file to be deleted permanently. How to send it to Recycle bin? Please help, Thanks in advance, -Regards, Dinesh
14
4108
by: Just Me | last post by:
Can anyone fix the code below? I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string With FileOperation ..wFunc = FO_DELETE ..pFrom =...
2
3898
by: Raymond Du | last post by:
Hi, I am working on a VB.Net window application, the application use System.IO.File.Delete method to delete files, can those deleted files be restored? TIA
4
3257
by: gsb58 | last post by:
Hi! I've been following the example on SHFILEOPSTRUCT here in the group, but I keep getting the message: 'Cannot read from sourcefile'. Here's the code: SHFILEOPSTRUCT shf = new...
6
2133
by: yxq | last post by:
Hello, The File.Delete(VS2005) function can not delete file on Vista-64bit, why? And, what changes of API between 32-bit and 64-bit? Thank you
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.