Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permanently delete files off harddrive.

Status
Not open for further replies.

gjsala

Technical User
Feb 20, 2003
107
US
I would like to permanently delete files from one folder on the c: drive off the c: drive. I have been using the following code to move files between folders but I would like to automate the process. Thanks for your help in advance!

Sub MoveFiles()
Dim strFolderA As String
Dim strFolderB As String
Dim strFile As String
Dim cnt As Long
On Error Resume Next

'//Change the path to the source folder, accordingly
strFolderA = "C:\Work\"

'//Change the path to the destination folder, accordingly
strFolderB = "C:\trash\"

If Right(strFolderA, 1) <> "\" Then strFolderA = strFolderA & "\"
If Right(strFolderB, 1) <> "\" Then strFolderB = strFolderB & "\"
'Identifies the file
strFile = Dir(strFolderA & "*.*")
''loop until no files are found
Do While Len(strFile) > 0
If Left(strFile, 1) <> "!" Then ''Looks for the "!" and will not move no matter the date
If (Date + Time) - FileDateTime(strFolderA & strFile) > 7 Then
cnt = cnt + 1
Name strFolderA & strFile As strFolderB & strFile
End If
End If
strFile = Dir
Loop
End Sub
 

If you want to Delete a file, use:
Code:
Kill "C:\SomeFolder\SomeFile.txt"

If you want to "permanently delete files", the problem is with the word: "permanently". You cannot. You can always use some utilities to retrive deleted files, but that's another story.....

Have fun.

---- Andy
 
Andy,
Another idea is to create a new folder, put the files that I want to put into that new folder then delete the file bypassing the trash can. How would I do that?

Thanks!
 

I just did [tt]Kill[/tt] on a text file and I do not have it in trash can. Do you have files in trash after the Kill?

Have fun.

---- Andy
 
Andy,
Thanks for your help. I did figure out how do delete the files without going to the trash.
 

In Windows Explorer you can do that by holding down Shift key while deleting a file - it does not go to Recycling Bin.

But if you have some nice fix for VBA, other people looking at this tread may want to know about it. So please share what you have.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top