Solved

Question about deleting files

Posted on 2003-11-11
8
615 Views
Last Modified: 2008-02-01
Is there any other way to delete a file other then using a FSO or the Kill method?

I have a computer that connectes to remote machines, and deletes files out of a specified folder if it is older then 5 days.  Everything works great, except i receive this error about half of the time:

Runtime error: -2147024832  Description: Method '~' of object '~' failed.

I seem to get it on any number of machines (there is 12 machines that i delete from).  I know it is not a hardware issue (bad hard drive, network issues, etc) because i can delete these files manually via windows (also working remotely, connected to the share).  I have my program dumping all information when it encounters this error, so i know which directory it was trying to delete.  Everything is fine, and i cant figure out what is causing this error.

Any ideas on this, or another way to delete files?

I have found information about it being a problem with windows, but only on windows 2000 or less (fixed after win2k SP1).  All of the PCs have the latest SP on them (all running windows 2000 SP4).  So i dont think that is the issue.

Explained in http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20736947.html

0
Comment
Question by:kmorris1186
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 24

Assisted Solution

by:R_Rajesh
R_Rajesh earned 25 total points
ID: 9720896
Hi kmorris1186,

found this snippet on the web, uses api:

Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
       pTo As String
        fFlags As Integer
      fAnyOperationsAborted As Boolean
        hNameMappings As Long
       lpszProgressTitle As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll"
        Alias  "SHFileOperationA" (lpFileOp As
        SHFILEOPSTRUCT) As Long

Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
'No user interface will be displayed if an error occurs.
Private Const FOF_NOERRORUI = &H400
Private Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.

Function KillToRecycleBin(ByVal strFileToDelete As String, _
Optional ByVal PromptUser As Boolean = False) As Long
    Dim lngFlags As Long
    Dim FileOperation As SHFILEOPSTRUCT
   
    lngFlags = FOF_ALLOWUNDO Or FOF_NOERRORUI
    If Not PromptUser Then lngFlags = lngFlags Or FOF_NOCONFIRMATION
   
    With FileOperation
        .wFunc = FO_DELETE
        .pFrom = strFileToDelete
        .fFlags = lngFlags
    End With
    ' Returns 0 if no error
     KillToRecycleBin = SHFileOperation(FileOperation)
End Function

To send a file to the recycle bin use:
KillToRecycleBin "C:\TheFileToDelete.txt"

To prompt the user to send a file to the recycle bin use:
KillToRecycleBin "C:\TheFileToDelete.txt", True

Cheers!
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9721005
do you think this would delete using the full UNC path?

Like "\\machinename\share\" ?

i will check it out, she what i can get it to do..

thanks
0
 
LVL 1

Expert Comment

by:Crazy_king_in
ID: 9721618
Try This

Paste this in the Form General section
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Then call
DeleteFile \\FileName
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:kmorris1186
ID: 9726279
would that also work with a whole directory?  I am actually deleting images out of folders.  If i delete the images one by one, it is real slow.  If i delete the directory as a whole, it is much faster.
0
 
LVL 1

Accepted Solution

by:
Crazy_king_in earned 50 total points
ID: 9728530
Try this

Public Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As Long

RemoveDirectory \\DirName
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9728643
oh, didnt think it would be that simple :)

i will give it a try! i am still revamping the whole GUI of my program.  Trying to make it more user friendly.  I will get back to in a day or so once i get to the deleting code section.

Thanks! i will try all 3 ways.

Nobody has any ideas about the "Method '~' of object '~' failed" error do ya?
0
 
LVL 2

Assisted Solution

by:cofneverlivetotell
cofneverlivetotell earned 25 total points
ID: 9729424
There is some kind of "purge" alternative to "kill"

look it up in MSDN


Cofneverlivetotell
cofneverlivetotell@hotmail.com
0
 
LVL 7

Author Comment

by:kmorris1186
ID: 9816737
Sorry this is taking em so long.  I havent had much time to finish this project up.

I have added 30 points since i am taking so long.

I havent forgotten. dont worry..
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 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