473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

apiSHFileOperat ion preventing Folder deletion

Hi,
I am unable to delete a subfolder that I have created programatically .
I am using a modification of the apiSHFileOperat ion 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(!File Name, 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 apiSHFileOperat ion;
Function fCopyAToB(strA As String, strB As String)As Long
....
With tshFileOp
.pFrom = strA & vbNullChar
.pTo = strB & vbNullChar
.fFlags = FOF_NOCONFIRMMK DIR + FOF_NOCONFIRMAT ION
End With
lngRet = apiSHFileOperat ion(tshFileOp)
fCopyAToB = (lngRet = 0)
End Function

Nov 13 '05 #1
1 1608
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_MULTIDESTFI LES.

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_NOCONFIRMMK DIR + FOF_NOCONFIRMAT ION & _
+ FOF_SIMPLEPROGR ESS + FOF_MULTIDESTFI LES
With tshFileOp
.wFunc = lngwFunc
.hwnd = hWndAccessApp
.pFrom = strFrom & vbNullChar & vbNullChar
.pTo = strTo & vbNullChar & vbNullChar
.fFlags = lngFlags
End With
lngRet = apiSHFileOperat ion(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
1832
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 data.mdb to another secure location every time a particular user who performs most of the data entry exits the database. Setting the windows permissions for the database folder to "read only" seems to create problems and data entry users obviously...
0
1536
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 okay, but now in .NET it is exceedingly too slow when attempting to delete large collections (roughly 10,000). It is on the order of 10 items deleted every 30 seconds. My function is as follows: Private Sub DeleteAllEntries()
3
1647
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 eBooks. Inside this folder I have some eBooks, such as eggrecipes.pdf If the user types in the URL <domain>/eBooks/eggrecipes.pdf the eBook eggrecipes.pdf will appear in the browser.
4
6739
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 folder is not deleted, but stays and becomes totally locked down. I can no longer open it in Windows Explorer and when I try to re-launch VS 2005 debug, it complains because it can no longer monitor that folder .. because it's denied access.
3
3876
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 have to set particular permissions on the server? Thank you in advance! Paolo
6
2620
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
7561
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 the folder but I get the error message when the procedure attempts to delete the folder selected in the BrowseforFolderbyPath function. How can I get it to delete the folder that the user has selected in the Browse for Folder dialog?
1
1541
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 think about the race conditions that exist between the process that will wake up to upload the files and the fact that the user can add additional files to the drop folder at any point in time. I would like to clear out files/folders after they have...
1
2115
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 directory when its being used by my application. I need to do like 1. open directory by application. 2. lock it by application. 3. deal with directory's content.
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5272
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.