Deleteing a folder on HD from Access

gbanks

Registered User.
Local time
Today, 20:58
Joined
Feb 9, 2000
Messages
161
Not sure if this can be done but I have a request to delete the contents of a folder on a users hard drive from in Access. Basically what they want to be able to do is click a button on a form and have it delete the contents of a folder called C:\tempdata. Is this possible? Thanks for the help....
 
Reference the microsoft scripting
then try this

Dim fso As New Scripting.FileSystemObject
fso.DeleteFolder "C:\Test", True
or
fso.deletefile


if all else fails,
myfile = dir("C:\Temp\*.*")
do while myfile <> vbnullstring
kill "C:\Temp\" & myfile
myfile = dir
loop

Regards
 
Here is some VB code I found some where that will delete a directory and all files within the directory [no matter what the files attributes are]. It does not require any references and it works in Access 97.

Place this in a public module...
Code:
Option Compare Database
Option Explicit

Public Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type

Public Const FO_DELETE = &H3
Public Const FOF_ALLOWUNDO = &H40
Public Const FOF_SILENT = &H4
Public Const FOF_NOCONFIRMATION = &H10
Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Function DeleteDir(strDirectory As String)
Dim SHFileOp As SHFILEOPSTRUCT

    With SHFileOp
        'Delete the file
        .wFunc = FO_DELETE
        'Select the file
        .pFrom = strDirectory
        'Move to recycle bin, no warning/confirmation messages, no progress meter
        .fFlags = FOF_ALLOWUNDO Or FOF_SILENT Or FOF_NOCONFIRMATION
    End With
    'perform file operation
    SHFileOperation SHFileOp

End Function
Here is the test function to try the code...
Code:
Public Sub Delete_Folder()

    If Dir("C:\Temp", vbDirectory) <> "" Then
        DeleteDir ("C:\Temp")
        MsgBox "The 'C:\Temp' folder was deleted!"
    Else
        MsgBox "nothing to delete"
    End If

End Sub
HTH
 
Make a little bat file.

You make them like this. Type at the C prompt

C:>Copy con filename.bat Hit Enter key

cd\tempdata Hit Enter key
Del *.* Hit Enter key
You now press Ctrl Z Hit Enter key
Hit Enter key

Then make a macro using RunApp action and enter c:\filename.bat

One you have made one of them you can go to Exploter and with Properties go to Edit and then type away your commands to hearts content. :D

Mike
 
Last edited:
ghudson said:
Why use DOS when VBA can do it for you?

Easier for me and often easier for other people. MY VBA is limited to being on form labels to open Word docs and even then they are simple as nearly all the actions are EditCopy and EditPaste to Word Bookmarks and running macros.

Also, if you want to make a lot of bat files as in the above exmple then I think they are much quicker to make, once you have the first one done. I have a lot of them them that mainly copy Word docs from a folder to another folder. These are Word docs that a fairly complex in terms of Access inserting data into Bookmarks and linking to queries so I have spares in another folder.

I also use .bat files for my backup to CDs

Mike
 
Mike375 said:
I also use .bat files for my backup to CDs
Can you get a batch file to write a file(s) directly to a CD burner?
 
ghudson said:
Can you get a batch file to write a file(s) directly to a CD burner?

Here is the contents of one that I use and it is running on XP Home and is run from a buttom on the Microsoft Office Shotcut bar from Office 95

c:
cd\
copy saveall.bat d:
copy save.bat d:
copy buscan.bat d:
copy restscan.bat d:
copy *.* d:
c:
Cd\
c:
cd\
cd\documents and settings\John Chorley\my documents
copy *.* d:
cd\
d:
md letters
cd\letters
c:
cd\letters
copy *.* d:
c:
cd\
d:
cd\
md Spareletters
cd\Spareletters
c:
cd\Spareletters
copy *.* d:
c:
cd\
cd\
d:
cd\
md A
cd\A
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\A
copy *.* d:
c:
Cd\
d:
cd\
md B
cd\B
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\B
copy *.* d:
c:
Cd\
d:
cd\
md C
cd\C
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\C
copy *.* d:
c:
Cd\
d:
cd\
md D
cd\D
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\D
copy *.* d:
c:
Cd\
d:
cd\
md E
cd\E
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\E
copy *.* d:
c:
Cd\
d:
cd\
md F
cd\F
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\F
copy *.* d:
c:
Cd\
d:
cd\
md G
cd\G
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\G
copy *.* d:
c:
Cd\
d:
cd\
md H
cd\H
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\H
copy *.* d:
c:
Cd\
d:
cd\
md I
cd\I
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\I
copy *.* d:
c:
Cd\
d:
cd\
md J
cd\J
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\J
copy *.* d:
c:
Cd\
d:
cd\
md K
cd\K
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\K
copy *.* d:
c:
Cd\
d:
cd\
md L
cd\L
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\L
copy *.* d:
c:
Cd\
d:
cd\
md M
cd\M
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\M
copy *.* d:
c:
Cd\
d:
cd\
md N
cd\N
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\N
copy *.* d:
c:
Cd\
d:
cd\
md O
cd\O
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\O
copy *.* d:
c:
Cd\
d:
cd\
md P
cd\P
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\P
copy *.* d:
c:
Cd\
d:
cd\
md Q
cd\Q
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Q
copy *.* d:
c:
Cd\
d:
cd\
md R
cd\R
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\R
copy *.* d:
c:
Cd\
d:
cd\
md S
cd\S
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\S
copy *.* d:
c:
Cd\
d:
cd\
md T
cd\T
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\T
copy *.* d:
c:
Cd\
d:
cd\
md U
cd\U
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\U
copy *.* d:
c:
Cd\
d:
cd\
md V
cd\V
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\V
copy *.* d:
c:
Cd\
d:
cd\
md W
cd\W
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\W
copy *.* d:
c:
Cd\
d:
cd\
md X
cd\X
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\X
copy *.* d:
c:
Cd\
d:
cd\
md Y
cd\Y
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Y
copy *.* d:
c:
Cd\
d:
cd\
md Z
cd\Z
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Z
copy *.* d:
c:
Cd\
d:
cd\
md PersonaLNonBus
cd\PersonaLNonBus
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\PersonaLNonBus
copy *.* d:
c:
Cd\
d:
cd\
md PersonaLBus
cd\PersonaLBus
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\PersonaLBus
copy *.* d:
c:
Cd\
d:
cd\
md ComputerOffice
cd\ComputerOffice
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\ComputerOffice
copy *.* d:
c:
Cd\
d:
cd\
md Guns
cd\Guns
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Guns
copy *.* d:
c:
Cd\
d:
cd\
md FAI
cd\FAI
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\FAI
copy *.* d:
c:
Cd\
d:
cd\
md SunAlliance
cd\SunAlliance
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\SunAlliance
copy *.* d:
c:
Cd\
d:
cd\
md Tyndall
cd\Tyndall
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Tyndall
copy *.* d:
c:
Cd\
d:
cd\
md Colonial
cd\Colonial
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Colonial
copy *.* d:
c:
Cd\
d:
cd\
md Zurich
cd\Zurich
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Zurich
copy *.* d:
c:
Cd\
d:
cd\
md AMP
cd\AMP
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\AMP
copy *.* d:
c:
Cd\
d:
cd\
md AXA
cd\AXA
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\AXA
copy *.* d:
c:
Cd\
d:
cd\
md MLC
cd\MLC
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\MLC
copy *.* d:
c:
Cd\
d:
cd\
md Tower
cd\Tower
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Tower
copy *.* d:
c:
Cd\
d:
cd\
md ACL
cd\ACL
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\ACL
copy *.* d:
c:
Cd\
d:
cd\
md Lumley
cd\Lumley
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Lumley
copy *.* d:
c:
Cd\
d:
cd\
md Temporary
cd\Temporary
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Temporary
copy *.* d:
c:
Cd\
d:
cd\
md ASIC
cd\ASIC
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\ASIC
copy *.* d:
c:
Cd\
d:
cd\
md DailyNotes
cd\DailyNotes
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\DailyNotes
copy *.* d:
c:
Cd\
d:
cd\
md CitiCorp
cd\CitiCorp
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\CitiCorp
copy *.* d:
c:
Cd\
d:
cd\
md ING
cd\ING
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\ING
copy *.* d:
c:
Cd\
d:
cd\
md InsuranceAllCo
cd\InsuranceAllCo
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\InsuranceAllCo
copy *.* d:
c:
Cd\
d:
cd\
md Norwich
cd\Norwich
c:
cd\Documents and Settings\John Chorley\My Documents\My PaperPort Documents\Norwich
copy *.* d:
 
Geez,

Wouldnt it have been easier to attach the file instead of the full content?

BR
 
That was pretty easy. Edit Select All Copy and paste into the posting. :D

The attach has not worked for me when trying to retrieve one and I have seen others say the same.

Mike
 

Users who are viewing this thread

Back
Top Bottom