Talk:Attrib: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
(Recursice attrib)
 
Line 1: Line 1:
  nsExec::ExecToLog 'attrib.exe -r "$INSTDIR\*.*" /s'
  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.
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

Latest revision as of 16:28, 13 February 2009

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