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

Turn off read only on all files in folders and subfolders

Status
Not open for further replies.

KOM

Programmer
Jun 26, 2001
1
US
Hello,

I'm new to vbscript and I'm looking for some help on how to turn the read only attribute off all the files in a folder/subfolders. I have looked for examples but everything I have found shows how to turn off only 1 file or 1 folder. I need to turn the read only attribute off several folders and files. Any help would be appreciated.
 
IF I understand your queston correctly, you can always shell out to dos and do a dir > test.

next edit the test file and remove everything but the file name, also ensure that there are no spaces in the stahdalne filenames. Next most editors have a change function so place a semicolon in front of all the files names and use the change function to canged the ; into attrib -r .

Now just rename the test file into test.bat and type test at the dos prompt.

Or like me, you can just write a quick program to do all the above and you can always change the attrib -r for what ever function you might need next.

BTW this is the old and dirty way but quick and flexable, good luck.
 
Use the FSO and use recursion:

Set oFSO = Createobject("Scripting.FilesystemObject")
Set oFolder = oFSO.GetFolder("C:\mydir")
nAttr=oFolder.Attributes
If nAttr and 1 Then oFolder.Attributes = nAttr - 1
For Each oFile In oFolder.Files
nAttr = oFolder.Attributes
If nAttr and 1 Then oFile.Attributes = nAttr - 1
Next
For Each oFold In oFolder.SubFolders
nAttr=oFold.Attributes
If nAttr and 1 Then oFold.Attributes = nAttr - 1
For Each oFile In oFold.Files
nAttr = oFolder.Attributes
If nAttr and 1 Then oFile.Attributes = nAttr - 1
Next
Next

Or as f1car eluded, use the DOS Attrib command:

Set oShell = CreateObject("WScript.Shell")
oShell.Run "Attrib -R C:\mydir\*.* /S",0

but, IIRC, it only works on files, not directories. Jon Hawkins
 
There is a sample free for downloading that will cover this it is at . Scroll down to SAMPLE PACK 2 - vbscripts5-25.zip and dowload it. In the zip file is the VBS file that performs the operation for you. Some changes may be required but nothing too tough.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top