|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
Modify File Attributes(Community)
Script Code
VBScript
Dim fso,i
Dim strStartFolder,age
Dim oFolder
Dim oFile
Dim colFiles
Dim colNargs,colUargs
Dim Display
Set fso = CreateObject("Scripting.FileSystemObject")
Set colNargs=WScript.Arguments.Named
If colNargs.Length<1 Then
WScript.Echo ("Missing Argument")
WScript.Echo ("change.vbs [/p:(path)] [/d:(true/false)] [/a:(age in days)]")
WScript.Echo("arguments: /p: full directory path, /d: to display on screen /a: age of file in days")
WScript.Echo ("ex: change.vbs /p:c:\ /d:True /a:65")
WScript.Echo("run change.vbs on c:\test, display to screen, change archive bit for files older than 65 days")
WScript.Echo("age must be numberic")
WScript.Echo("defaults: path - c:\")
WScript.Echo(" display false")
WScript.Echo(" age - 2 days")
WScript.Echo("the age switch must not be the last one!")
WScript.Quit
End If
'------check each option----------
If colNargs.Exists("p") Then
strStartFolder=colNargs.Item("p")
Else
WScript.Echo("Missing path")
WScript.Quit
End If
If colNargs.Exists("a") Then
If IsNumeric(colNargs.Item("a")) Then
age=CInt(colNargs.Item("a"))
Else
WScript.Echo("Age must be a value")
WScript.Quit
End If
End If
If colNargs.Exists("d") Then
Display=colNargs.Item("d")
If UCase(Display)="TRUE" Then Display=True Else Display=false
End If
Set oFolder = fso.GetFolder(strStartFolder)
If Display Then
Wscript.Echo oFolder.Path
End If
ShowFiles oFolder.Files
ShowFolders fso.GetFolder(strStartFolder)
Set fso=Nothing
Set oFolder=Nothing
Set colFiles=Nothing
Set colNargs=Nothing
WScript.Quit
Sub ShowFolders(Folder)
For Each Subfolder in Folder.SubFolders
If Display Then
WScript.Echo Subfolder.Path
End If
Set oFolder = fso.GetFolder(Subfolder.Path)
Set colFiles = oFolder.Files
ShowFiles colFiles '-----show all files of folder------
ShowFolders Subfolder '-----show current folder-------
Next
End Sub
Sub ShowFiles(Folder)
Dim fDate '----file date------
Dim att '----file attributes---
Dim fName '----file name-------
Dim msg '----attribute message----
For Each oFile in Folder
fDate=oFile.DateLastModified '----vars for easy reading-----
att=oFile.attributes
fName=oFile.Name
If CDate(fDate)> Date-age Then
If Display Then
msg=""
If att And 32 Then msg=msg & "Archive "
If att And 2 then msg=msg & "Hidden "
If att And 1 Then msg=msg & "Read-Only "
If att And 4 Then msg=msg & "System "
If att And 128 Then msg=msg & "Compressed"
Wscript.Echo fName & " - " & fDate & " : " & msg
WScript.Echo("Changing Archive Bit to - " & (att=att And 2))
End if
oFile.attributes=att Xor 32
End If
Next
End Sub
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.
|