473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

apiSHFileOperation preventing Folder deletion

Hi,
I am unable to delete a subfolder that I have created programatically.
I am using a modification of the apiSHFileOperation by Dev Ashish
(http://www.mvps.org/access/api/api0026.htm) to copy the files.

A File Copy function is called as part of a loop to copy a series of
files from a variety of locations that are stored in the database. All
the files are copied to a folder specified by the user. Once the user
has used this folder (to write a CD of the files) he is supposed to be
able to delete it. However, for as long as Access remains open, it keeps
a handle on this directory it has created, preventing Windows from
deleting the folder. The files within the folder can be deleted, but not
the folder itself.

This is a bit of an inconvenience, but mostly I am not too keen on using
code that I don't comprehend. Can anyone point me to how to make Access
release the folder? Perhaps I am not terminating the operation correctly?

Thanks in advance
Eike

Bits of code below:

##this is within the main Sub, it retrieves the recordset, then calls
the file copy function for each item;
With rsSelected
.MoveFirst
Do While Not .EOF
If fCopyAToB(!FileName, txtCopyFolder) <> True Then
MsgBox "Abandoning File Copy Process" & vbNewLine & "There was
an error writing....", vbOKOnly & vbCritical, AppnName
GoTo Leave_Sub
End If
.Edit
![CD-id] = txtCDID
!Temp = False
.Update
.Bookmark = .LastModified
.MoveNext
Loop
End With

##Here is the functional bit of the apiSHFileOperation;
Function fCopyAToB(strA As String, strB As String)As Long
....
With tshFileOp
.pFrom = strA & vbNullChar
.pTo = strB & vbNullChar
.fFlags = FOF_NOCONFIRMMKDIR + FOF_NOCONFIRMATION
End With
lngRet = apiSHFileOperation(tshFileOp)
fCopyAToB = (lngRet = 0)
End Function

Nov 13 '05 #1
1 1559
I have solved my own problem; guess I should have delved around at MSDN
a little more before asking. Rather than calling SHFileOperation for
each file to be copied, I compiled a list of the files to be copied,
each separated by vbNullChar. The two strings of source and destination
files are then passed to the SHFileOperation with the flag
FOF_MULTIDESTFILES.

This way Access does not hang onto any of the folders created so they
can be deleted by the user as and when. I guess just using the call
properly stops my original error from occuring. The simplified code I
have used is below, in case anyone else wants it:

'first loop through the set and create a list of source and destination
files
With rsSelected
.MoveFirst
Do While Not .EOF
strLstFrom = strLstFrom & vbNullChar & !FileName
strLstTo = strLstTo & vbNullChar & !FileName
.MoveNext
Loop
End With

'now call the copy function, trim the leading vbNullChar first
Func_Copy(Right(strLstFrom, Len(strLstFrom) - 1), & _
Right(strLstTo, Len(strLstTo) - 1))

and in Dev's function I used these flags:
lngFlags= FOF_NOCONFIRMMKDIR + FOF_NOCONFIRMATION & _
+ FOF_SIMPLEPROGRESS + FOF_MULTIDESTFILES
With tshFileOp
.wFunc = lngwFunc
.hwnd = hWndAccessApp
.pFrom = strFrom & vbNullChar & vbNullChar
.pTo = strTo & vbNullChar & vbNullChar
.fFlags = lngFlags
End With
lngRet = apiSHFileOperation(tshFileOp)
Func_Copy = (lngRet = 0)

Nov 13 '05 #2

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

Similar topics

1
by: Wayne Aprato | last post by:
Is there an effective method of preventing users from accidentally or maliciously deleting the database file/files from a shared network drive? At the moment, I'm using a batch file to copy the...
0
by: steven.shannon | last post by:
Hello, I'm writing an app that involves deleting all the items in a specified Outlook folder regardless of item type (i.e. Contacts, Tasks, etc.). This code was ported from VBA where it worked...
3
by: samadams_2006 | last post by:
I have a Web Site that I'm interested in selling eBooks from. I'm having a problem setting it up as I would like, and hope that someone can help me out. Inside my domain I have a folder called...
4
by: Zeb | last post by:
Hi I'm using DirectoryInfo.Delete so that when a product is removed, all it's associated images (including the folder they sit in) are deleted. This actually seems to work fine. However, the...
3
by: =?Utf-8?B?UGFvbG8gTmljY29sw7IgR2l1YmVsbGkgW0F4ZXR0 | last post by:
I have a website with a public folder (users can upload images into it) so I'm wondering if it's possible to avoid the deletion of this folder when I re-publish the website from visual studio. Do I...
6
by: pankajprakash | last post by:
hi, i have a windows form and there is a text box to select the file of folder to delete. i need a progress bar during the file of folder deletion.
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
1
by: Larry Bates | last post by:
I have a need to implement a drop folder upload mechanism for secure uploading of files to a server. At first glance this appears that it would be an easy application to write. Then I begin to...
1
by: miztaken | last post by:
Hi there, My C# application opens a directory and deals with the files inside it. But at the mean time i can delete the directory from windows. Is there any way i can restrict the deletion of that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.