如何使用VBA删除文件? [英] How to use VBA to delete files?

查看:143
本文介绍了如何使用VBA删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种快速而又脏的方法来删除给定目录中的所有文件?

可能是这样的:


设置objFile = CreateObject(" ; Scripting.FileSystemObject")

objFile.DeleteFile" C:\ Temp"中的所有文件''如何指定目录?


我是否需要使用Windows API?

私有声明函数FindFirstFile Lib" kernel32 Alias

" FindFirstFileA" (ByVal lpFileName As String,lpFindFileData As

WIN32_FIND_DATA)As Long


我要做的是维护一个文件的备份目录

超链接到我的Access 2003 mdb中的各种记录。所有超链接

都存储在一个表中,因此只需使用FileCopy将

文档复制到备份目录即可。但首先我要清除任何现有文件的备份

目录...如何获取

目录中的文件列表?

提前致谢...

Is there a quick and dirty way to delete all files in a given directory?
perhaps something like this:

Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile "all files in C:\Temp" ''how to specify directory?

Do I need to use the Windows API?

Private Declare Function FindFirstFile Lib "kernel32 Alias
"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As
WIN32_FIND_DATA) As Long

What I''m trying to do is maintain a backup directory of documents that are
hyperlinked to various records in my Access 2003 mdb. All the hyperlinks
are stored in a table, so it''s just a matter of using FileCopy to copy the
documents to the backup directory. But first I want to purge the backup
directory of any existing files... how to get a list of files in the
directory?

Thanks in advance...

推荐答案



" deko" < DJ **** @ hotmail.com>在消息中写道

新闻:ST ***************** @ newssvr25.news.prodigy.co m ...

"deko" <dj****@hotmail.com> wrote in message
news:ST*****************@newssvr25.news.prodigy.co m...
是否有一种快速而又脏的方法来删除给定目录中的所有文件?
可能是这样的:

设置objFile = CreateObject(" Scripting.FileSystemObject")
objFile.DeleteFileC:\ Temp中的所有文件''如何指定目录?

我是否需要使用Windows API?

私有声明函数FindFirstFile Lib" kernel32 Alias
" FindFirstFileA" (ByVal lpFileName As String,lpFindFileData As
WIN32_FIND_DATA)长期

我要做的是维护一个备份目录,其中包含多个链接到各种记录的文档。我的Access 2003 mdb。所有超链接都存储在一个表中,因此只需使用FileCopy将
文档复制到备份目录即可。但首先我要清除任何现有文件的备份目录...如何获取
目录中的文件列表?

提前致谢...
Is there a quick and dirty way to delete all files in a given directory?
perhaps something like this:

Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile "all files in C:\Temp" ''how to specify directory?

Do I need to use the Windows API?

Private Declare Function FindFirstFile Lib "kernel32 Alias
"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As
WIN32_FIND_DATA) As Long

What I''m trying to do is maintain a backup directory of documents that are
hyperlinked to various records in my Access 2003 mdb. All the hyperlinks
are stored in a table, so it''s just a matter of using FileCopy to copy the
documents to the backup directory. But first I want to purge the backup
directory of any existing files... how to get a list of files in the
directory?

Thanks in advance...




Kill(" D:\ NewwFolder \ *。*")





Kill ("D:\NewFolder\*.*")




On Tue,23 Dec 2003 01:29:22 GMT in comp.databases.ms-access,deko

< dj **** @ hotmail.com>写道:
On Tue, 23 Dec 2003 01:29:22 GMT in comp.databases.ms-access, "deko"
<dj****@hotmail.com> wrote:
是否有一种快速而又脏的方法来删除给定目录中的所有文件?
可能是这样的:

设置objFile = CreateObject(" Scripting.FileSystemObject")
objFile.DeleteFile" C:\ Temp"中的所有文件''如何指定目录?

我是否需要使用Windows API?

私有声明函数FindFirstFile Lib" kernel32 Alias
" FindFirstFileA" (ByVal lpFileName As String,lpFindFileData As
WIN32_FIND_DATA)As long


搜索kill的帮助

我想要的是什么do是维护一个备份目录,该目录是链接到Access 2003 mdb中各种记录的文档。所有超链接都存储在一个表中,因此只需使用FileCopy将
文档复制到备份目录即可。但首先我要清除任何现有文件的备份目录...如何获取
目录中的文件列表?
Is there a quick and dirty way to delete all files in a given directory?
perhaps something like this:

Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile "all files in C:\Temp" ''how to specify directory?

Do I need to use the Windows API?

Private Declare Function FindFirstFile Lib "kernel32 Alias
"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As
WIN32_FIND_DATA) As Long
Search help for "kill"
What I''m trying to do is maintain a backup directory of documents that are
hyperlinked to various records in my Access 2003 mdb. All the hyperlinks
are stored in a table, so it''s just a matter of using FileCopy to copy the
documents to the backup directory. But first I want to purge the backup
directory of any existing files... how to get a list of files in the
directory?




Dim strTmp as String

Dim strFile()as String

Dim lngNumFiles as Long

Dim i As

strTmp = Dir



Dim strTmp as String
Dim strFile() as String
Dim lngNumFiles as Long
Dim i As long
strTmp = Dir


(" c:\ foo \\\\ * *。*")

执行len(strTmp)

lngNumFiles = lngNumFiles + 1

Redim保留strFile(1到lngNumfiles)

strFile(lngNumFiles)= strTmp

strFile = Dir
("c:\foo\bar\*.*")
Do while len(strTmp)
lngNumFiles = lngNumFiles + 1
Redim preserve strFile(1 to lngNumfiles)
strFile(lngNumFiles) = strTmp
strFile = Dir


这篇关于如何使用VBA删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆