Talk:Attrib

From NSIS Wiki
Jump to navigationJump to search
nsExec::ExecToLog 'attrib.exe -r "$INSTDIR\*.*" /s'

accomplishes the same thing. attrib.exe should be available and in the path of any Windows machine ever.

I was looking for a recursive version of Attrib and bumped across this : http://nsis.sourceforge.net/RecFind:_Recursive_FindFirst%2C_FindNext%2C_FindClose

I adapted Attrib by shamelessly copying the example in the above cited url :

Function RecursiveAttrib
  Exch $1 ; Dir
  ${RecFindOpen} $1 $R0 $R1
  ${RecFindFirst}
   IfFileExists "$R0\$R1\*.*" Found
   SetFileAttributes "$1$R0\$R1" 0
   ${RecFindNext}
   Found:
${RecFindClose}
FunctionEnd

Calling this using the same syntax as the original Attrib function, that is :

Push $INSTDIR\
Call RecursiveAttrib

does the action (SetFileAttributes) on the files recursively.

Advantages I find :

  • no dependency on attrib.exe (although it should be there 99.9% of the time)
  • no ugly black cmd.exe flashing during the install process
  • possibility of doing some other operation than setting file attributes