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

问题描述

我有一个像'exportreport'这样的文件夹里面有60到70个不同的文件夹。

现在我想用vbscript删除所有子文件夹中的文件,我试过这个:



I have one folder like 'exportreport' having 60 to 70 different folders inside.
Now i want to delete files from all subfolders using vbscript, I have tried this:

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("D:\exportreport\*.xls"), DeleteReadOnly

推荐答案

sub RecursiveDeleteByExtension(byval strDirectory,strExtensionsToDelete)
	DIM objFolder, objSubFolder, objFile
	DIM strExt

	set objFolder = objFSO.GetFolder(strDirectory)
	for each objFile in objFolder.Files
		for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
			if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
				wscript.echo "Deleting:" & objFile.Path
				objFile.Delete
				exit for
			end if
		next
	next
	for each objSubFolder in objFolder.SubFolders
		RecursiveDeleteByExtension objSubFolder.Path,strExtensionsToDelete
	next
end sub


这篇关于如何从子文件夹中删除特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:28
查看更多