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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing file attributes of all files in a directory

Status
Not open for further replies.
Joined
Mar 22, 2012
Messages
2
Location
US
I have a script that will delete certain files, that are older than 30 days, within a folder and its subfolders.

Here's the problem, some of those files are read only. I need help creating a script that will change all of the files in a folder and it's subfolders to read/write so the files can be deleted because endusers are getting "permission denied" on certain files.

Please let me know if you need the script first.
 
OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders

strFolder = "C:\NRTEcho\CSDOCS\"

includeSubfolders = true

strExtensionsToDelete = "DOC,doc,XLS,xls,PDF,pfd,PRF,prf,PPT,ppt"

maxAge = 30

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders

'wscript.echo "Finished"

sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
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 "loop"
IF objFile.DateLastModified < (Now - MaxAge) THEN
' wscript.echo "Deleting:" & objFile.Path & " | " & objFile.DateLastModified
' wscript.echo "before delete"
objFile.Delete
' wscript.echo "after delete"
exit for
END IF
end if
next
next
if includeSubFolders = true then ' Recursive delete
for each objSubFolder in objFolder.SubFolders
DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
next
end if
end sub
 
Why not simply this ?
objFile.Delete [!]True[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top