Jump to content


Photo

Remove Read-Only Attribute for [Entire] Folder Contents


  • Please log in to reply
18 replies to this topic

#1 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 16 January 2006 - 04:53 PM

When restored from a CD Backup, the files & folders are copied with the Read-only attribute to hard-drive. It is quite annoying to remove the flag, especially when the folders contains many subfolders.

a simple line of AHK command would clear it all
FileSetAttrib, Attributes [, FilePattern, OperateOnFolders?, Recurse?]

My script extends the facility to Windows Explorer's Context Menu

A Screen shot of Windows Explorer's Context Menu Image: 640x480 13.2KB
Posted Image

1) Script will run only as an executable. Compile this code before attempting execution.
2) Run the executable once (without any parameter(s)), and it adds entries in Windows Registry, enabling a menu-item in right-click Context Menu of Windows Explorer. Also, it creates a shortcut to remove the Registry Entries made by the script
3) Registry entry will be pointing to the folder from where you executed the .EXE. You have to execute the .EXE again if you move it to a different location.
4) Tested the Script in Windows 98 SE and Windows XP Pro and it works fine.

Here follows the 90x90
FolderName=%1%
#NoTrayIcon
#SingleInstance off
if A_IsCompiled != 1
	{
	MsgBox,16,Error: %A_ScriptName%
	,Compile  "%A_ScriptName%"  into an Executable,10
	GoSub,Exitt
	}

if FolderName=
	GoSub,AddRegEntries

If FolderName= /UnInstall
	GoSub,UnInstall

IfNotExist,%FolderName%
	GoSub,Exitt

StringRight,LastChar,FolderName,1
	if LastChar != \
		FolderName=%FolderName%\

Files=%FolderName%*.*
FileSetAttrib,-R,%Files%,1,1

ControlSetText , msctls_statusbar321, Read-Only Removed,A
Tooltip,ReadOnly Attribute removed for`n%Files%
Sleep,3000
Tooltip
return
; ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~
AddRegEntries:
RegCommand="%A_ScriptFullPath%" "`%1`%"
RegRead, EntryInRegistry, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command

	L1=Open Windows Explorer, Right-click on any folder and
	L2=select "Remove Read-Only Attribute"
	L3=Entire Folder contents [including Sub-folders and
	L4=its contents] will be flagged READ/WRITE
	L5= UnInstall:     %A_ScriptName% /UnInstall

if RegCommand != %EntryInRegistry%
	{
	L0=%A_ScriptName%: Added Entries to Windows Registry

	RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly
	,, Remove Read-Only Attribute
	RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command
	,,"%A_ScriptFullPath%" "`%1`%"

	if ErrorLevel != 1
		msgbox,64,%L0%,%L1%`n%L2%`n`n%L3%`n%L4%`n`n%L5%
	else
		Msgbox,64,%A_ScriptName%: Error!
		,Unable to Add Entries to Windows Registry!

	FileCreateShortcut, %A_ScriptFullPath%
	,%A_ScriptDir%\Remove Registry Entries [added by %A_ScriptName%].LNK
	, %A_ScriptDir%
	, /UnInstall
	}
else
	msgbox,48,%A_ScriptName%: Already Installed,%L1%`n%L2%`n`n%L3%`n%L4%`n`n%L5%

GoSub,Exitt
return
; ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~
UnInstall:
RegDelete, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly
FileRecycle,%A_ScriptDir%\Remove Registry Entries [added by %A_ScriptName%].LNK
	if ErrorLevel != 0
	{
		L0=%A_ScriptName%: Error!
		L1=Unable to Remove Entries from Windows Registry!
	}
	else
	{
		L0=%A_ScriptName%: Removed Entries from Windows Registry
		L1=You can safely delete "%A_ScriptName%" now!
		L2=Execute "%A_ScriptName%" again to ReInstall
	}
msgbox,64,%L0%,%L1%`n%L2%
return
; ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~
Exitt:
ExitApp
return
; ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~ ~.'.~
;Script Written by Goyyah [2006-01-15], Last Modified [ 2006-01-17 ]

Post your Comments/Suggestions

Posted Image

#2 Serenity

Serenity
  • Members
  • 1271 posts

Posted 16 January 2006 - 06:34 PM

I created something similar a while ago. You can actually run a script from the context menu by specifying the path to AutoHotkey first. Here's an example:

title = Test

if A_IsCompiled =
{
  ; get path of autohotkey install: 
  regread, ahkpath, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AutoHotkey.exe

  ; install context menu entry:
  regwrite, REG_SZ, HKCR, Directory\Shell\%title%\command, , "%ahkpath%" "%A_ScriptFullPath%" "`%1"
  if errorlevel = 0
    msgbox, , %title%, Installation was successful!
  ; etc
}


#3 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 16 January 2006 - 09:15 PM

Thanks for the Info Serenity. It did not strike me in the first place.
I will try it and post the changes here. :-)

#4 jballi

jballi
  • Members
  • 941 posts

Posted 16 January 2006 - 10:10 PM

RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command 
   ,,"C:\Program Files\i-Keys\System\i-Attrib\i-Attrib.exe" "`%1`%"

The registry entry points to a static location. As described in your notes, it should point to a dynamic location.

I think you may have published an old version?? I certainly would be interested in the latest version.

#5 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 17 January 2006 - 05:03 AM

Code Updated:

Line #47

RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command
,, "C:\Program Files\i-Keys\System\i-Attrib\i-Attrib.exe" "`%1`%"


RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command 
   ,,"%RegCommand%" "`%1`%"



I guess I have been working on two instances of Metapad. The final save was given on the older one.

Thanks jballi .

#6 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 17 January 2006 - 05:45 AM

I was wrong again :(

Line #47 has been updated as follows
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, Folder\Shell\Remove ReadOnly\Command 
   ,,"%A_ScriptFullPath%" "`%1`%"


#7 Serenity

Serenity
  • Members
  • 1271 posts

Posted 17 January 2006 - 12:44 PM

For users who do not have the status bar enabled in Explorer, you might want to use another method to notify the user of completion of task, eg. msgbox.

ControlSetText , msctls_statusbar321, ReadOnly Attrib removed for %Files%,A


#8 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 17 January 2006 - 02:13 PM

Serenity

Good suggestion.. How do I check whether the Status bar is turned ON/OFF?

I want to pop-up the MsgBox only if Status Bar is disabled

I tried both the following but I get an empty variable

GuiControlGet,IsEnabled,Enabled,msctls_statusbar321

and

GuiControlGet,IsVisible,Visible,msctls_statusbar321

Also I tried

StatusBarGetText, StatusBarText,1,A

and

ControlGetText, StatusBarText,msctls_statusbar321,A

but both the above retrieves the text though DetectHiddenText is OFF.

Any suggestions? I've been trying in WIN98-SE

#9 Serenity

Serenity
  • Members
  • 1271 posts

Posted 17 January 2006 - 04:34 PM

The settings for Explorer are stored in the registry. You could use RegShot before and after enabling the status bar to determine what value to change.

#10 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 17 January 2006 - 05:57 PM

Serenity, I checked with RegShot.
That kind of alteration will be too much for me, I guess :shock:
Better I put a MsgBox or Display a Tooltip

Thanks

#11 WayneDZ

WayneDZ
  • Guests

Posted 26 September 2006 - 07:11 PM

I am very New to Scripts, how do I Compile this code?

#12 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 26 September 2006 - 07:17 PM

how do I Compile this code?


You need to download and install AutoHotkey.
Save any such code you find in this forum with an .AHK extension.
Right click on that file ( maybe from Windows Explorer ) and select
"compile script". That is it!

BTW, I coded this for Windows 98 .. It is not required for Windows 2000 & greater, I guess!

Regards, :)

#13 Waynedz

Waynedz
  • Guests

Posted 03 October 2006 - 01:53 PM

Thank you very much it worked like a charm.

I do have one other small question. I need to have a folder remove the Read Only Attribute automatically every day. I am attempting to use AutoHotkey to accomplish this but can't seem to make it work.

Any thoughts?

#14 PhiLho

PhiLho
  • Fellows
  • 6850 posts

Posted 03 October 2006 - 02:31 PM

Note that for such task, I just do an empty search on the folder, so it brings back all files and folders. Sort of type to get folders on top, select the files, hit Alt+Enter, click on read-only, done.
Just to give a simple alternative.

Waynedz, another way could be to use XXCOPY to do the task. I don't remember right know the relevant parameters, but I can find them back. Of course, you can code this with AHK too. Actually, looking harder at Goyyah's message, he give the only needed line at the top of the topic (FileSetAttrib with recurse option), the remainder is just fluff to put it in the context menu...

#15 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 03 October 2006 - 09:38 PM

I need to have a folder remove the Read Only Attribute automatically every day.


#NoEnv
; Self Installation part
if (A_scriptDir!=A_StartupCommon) {
   FileCopy, %A_ScriptFullpath%, %A_StartupCommon%,1
   FileDelete, %A_ScriptFullpath%
   Transform, FileName, Deref, %A_StartupCommon%\%A_ScriptName%
   SplitPath,A_ScriptName,,,,LinkFile
   FileCreateShortCut, %FileName%, %LinkFile%.LNK
   PostMessage, 0x111, 28931,,, ahk_class Progman
   ExitApp
   }

/*
You may delete the lines above after first run.
The actual script is below.
*/

#NoEnv
Files := "[color=red]C:\MyFolder\*.*[/color]"
FileSetAttrib,-R,%Files%,1,1
ExitApp

Copy and paste the above code in an editor.
Alter the folder name (in red color) to suit your need.
Save it as Attrib-R.AHK.
Exit the Editor. <- Important
Run the file by double-clicking it!

Do not hesitate to post for further clarifications!

Regards, :)