dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 12, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Clear File Attributes From Entire Directory Tree of Files


This function removes attributes from files in the folder you specify in strFolder. It also can walk down all subfolders of this folder recursively. This function was written mainly for removing the read-only flag that all files have after you copy a bunch from a CD (oldattribute = vbReadOnly), but you can use it with other attributes as well. Look for the other constants for file attributes in the object browser (subset scripting). To use this function, you must first set a Reference to the "Microsoft Scripting Runtime":
 
Option Explicit
Private fso As New Scripting.FileSystemObject
Public Function ClearAttribute(strFolder As _
String, fIncludeSubfolders As Boolean, _
oldAttribute As VbFileAttribute) As Long
Dim fld As Scripting.Folder
Dim subfld As Scripting.Folder
Dim file As Scripting.file
Dim lngCount As Long
Set fld = fso.GetFolder(strFolder)
For Each file In fld.Files
If file.Attributes And oldAttribute Then
file.Attributes = file.Attributes _
And Not oldAttribute
' Count the files
lngCount = lngCount + 1
End If
Next file
If fIncludeSubfolders Then
For Each subfld In fld.SubFolders
' Add total from this subfolder
' And its subfolders
lngCount = lngCount + _
ClearAttribute(subfld.Path, _
True, oldAttribute)
Next subfld
End If
' Number of total processed files
ClearAttribute = lngCount
End Function
Hans Weichselbaumer
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date