WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Version and Dir Mgmt

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Recursively Set Attributes on Files within Directories

Keywords: 	 recursive set file attributes

This WinBatch script is useful for changing the attributes of all files in a folder and its sub folders to read write. This is useful when files are copied from a CD to a hard disk. Windows itself automatically sets file attributes to 'read only' when files are copied from CDs to other media. If these files need to be edited, the file attributes will need to be 'read write'. This script does that quickly for all the files within a folder. Just put attrset.wbt in that folder and run it from there.

The extender is used to apply the settings to files in sub folders. This has many other applications.

strTitle = "Attribute Setter"
strAskLineBoxPrompt = "Upper case sets, lower unsets attributes.%@CRLF%%@CRLF%R readonly, A archive, S system, H hidden%@CRLF%Note: A is set when file has NOT been backed up."
strSetAttributes=AskLine(strTitle,strAskLineBoxPrompt,"r")
strStartDirectory=AskLine(strTitle,"Enter a starting directory.","C:\temp")

x=0
filea=""
msg="This example will change files from %strStartDirectory% down."
BoxOpen(strTitle,"%x% files changed.")
Pause(" ",msg)

AddExtender("wsrch34I.dll") ; This adds the text search extender.
handle=SrchInit(strStartDirectory,"*.*","","",16)
dStart = TimeYmdHms()
While 1

   filea=SrchNext(handle)
   If filea=="" Then Break

   ; lower case r a s and h set to off the read only, archive, system
   ; and hidden attributes. Capitalized RASH sets the attributes.
   ; Only one attribute designation is required. The other three
   ; are optional. Change the "rash" to the setting you require.
   ; On archive bits: New files are created with the attribute bit
   ; A set to on. To reset all files to unbacked condition use
   ; this setting string: "A". That's right, just a capital A.

   FileAttrSet(filea,strSetAttributes)
   x=x+1
   If x mod 10 == 0 Then BoxText("%x% files changed.")
EndWhile

dEnd = TimeYmdHms()
dDiff = TimeDiffSecs(dEnd,dStart)

SrchFree(handle)
BoxShut()
Delay(1)
Message(strTitle,"%x% files changed.")
Message(strTitle,"%dDiff% seconds elapsed.")

Article ID:   W14496
Filename:   Recursively Set Attributes on Files.txt
File Created: 2006:05:03:07:13:02
Last Updated: 2006:05:03:07:13:02