|
-
Dec 19th, 2007, 09:57 PM
#1
Thread Starter
New Member
FSO: delete dir, its files and subdirs & write list to text file
I am using VB6. I have a list of specific files that I need to delete from a Windows file system. I also have a list of directories (whose files and subdirectories can be deleted) that I need to delete.
Even though I know which files and directories I need to delete, I need to be able to show a log of which files were actually deleted.
I am using the FileSystemObject in the Microsoft Runtime Object Library. I know how to use the delete methods of the file and folder objects. I also know how to create a text file in the correct location in the file system.
I need to have a list of all files which have been deleted (with the full path, file name and extension) written to a text file. I am having trouble getting the list written to a text file.
I am listing the folders and files that need to be deleted like this:
folderDelete "c:\Application\WcBcBarcode"
folderDelete "c:\Program Files\WcBcBarcode"
folderDelete "c:\Platform\WcBc"
fileDelete "c:\Application\Startup\WcBcBarcode.exe"
fileDelete "c:\Application\Startup\WcBcBarcode.lnk"
fileDelete "c:\Application\WcBcBarcode.cpy
the sub routines for folderDelete and fileDelete look like this:
Sub fileDelete (fileName)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(fileName) Then objFSO.DeleteFile(fileName)
EndSub
Sub folderDelete (folderName)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(folderName) Then objFSO.DeleteFolder(folderName)
EndSub
I thought that it would be easy to get the specified "files" into the text file by:
1. declaring a file variable
2. using the CreateTextFile method to specify the name and location for the text file
3. using WriteLine or Write in a manner such as: WriteLine("Deleted: " & fileName)
But I was not able to get it to work.
And, for listing the files in the directories which were deleted, I thought that I should use GetFolder and pass the file names (and full paths) to an array, and then write the array to the text file.
I was not able to get this to work, either.
Can someone please help me to do the following:
1. pass the file names of the files in the directories (and the directory paths themselves) which are being deleted to a list or an array. (shouldn't this happen in the deleteFolder sub routine?)
2. write that list or array to the text file (shouldn't this happen in the deleteFolder sub routine?)
3. write the list of specified files that are being deleted to the text file (shouldn't this happen in the deleteFile sub routine?)
Your help is greatly appreciated.
Last edited by tuonela; Dec 31st, 2007 at 04:33 PM.
Reason: clarification
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|