Attrib: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
(Removed the comment about not being sure if SetFileAttributes now works. It does not.)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|sunjammer}}
|<small>Author: [[{{ns:2}}:sunjammer|sunjammer]] ([[{{ns:3}}:sunjammer|talk]], [[{{ns:-1}}:Contributions/sunjammer|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
A small NSIS script function written by Hendri Adriaens aka [[user:Smile2Me | Smile2Me]] that applies file attributes to many files at once.
A small NSIS script function written by Hendri Adriaens aka [[user:Smile2Me | Smile2Me]] that applies file attributes to many files at once.
Line 10: Line 8:
<highlight-nsis>SetFileAttributes "DIR\*.*" NORMAL</highlight-nsis>
<highlight-nsis>SetFileAttributes "DIR\*.*" NORMAL</highlight-nsis>


does not work." I'm not sure if the comment about SetFileAttributes not working is still correct.
does not work.


== The Script ==
== The Script ==
Line 68: Line 66:
FunctionEnd</highlight-nsis>
FunctionEnd</highlight-nsis>


[[{{ns:14}}:Disk, Path & File Functions]]
[[Category:Disk, Path & File Functions]]

Latest revision as of 14:34, 30 March 2007

Author: sunjammer (talk, contrib)


Description

A small NSIS script function written by Hendri Adriaens aka Smile2Me that applies file attributes to many files at once.

Hendri said at the time "I created it for Eduardo R. Puntel. He created an installer that copies files from CD to harddisk and wanted the program to be able to edit all files after install. The script changes the FileAttribute of all files in a dir to a preset value. Edit the script a bit to customise to your required FileAttributes for the files. The script can be used as a workaround since

SetFileAttributes "DIR\*.*" NORMAL

does not work.

The Script

outfile attrib.exe
name attrib
 
; Attrib
;
; Script to quickly set the FileAttribute
; of many files in a dir.
;
; Usage:
; Push "Dir"
; Call Attrib
;
; Notice that SetFileAttributes cannot take
; variables as "Attribute" so edit the script
; if you want some other attribute(s) to be
; assigned to the files.
;
; This might be a handy script when copying
; files from CD that need to be edited later.
;
; By: Hendri Adriaens
;     HendriAdriaens@hotmail.com
 
Section
; The demo zip includes two text-files.
; Check that they are "read-only" and
; then compile and run the script.
Push $EXEDIR\prob
Call Attrib
Sectionend
 
Function Attrib
  Exch $1 ; Dir
  Push $2
  Push $3
  FindFirst $2 $3 "$1\*.*"
  StrCmp $3 "" exitloop
  loop:
  StrCmp $3 "" exitloop
  StrCmp $3 "." next
  StrCmp $3 ".." next
  IfFileExists "$1\$3\*.*" next
  ; SetFileAttributes does not accept variables as attribute,
  ; so manually set this to the necessary value.
  SetFileAttributes "$1\$3" 0
  next:
  FindNext $2 $3
  Goto loop
  exitloop:
  FindClose $2
  Pop $3
  Pop $2
  Pop $1
FunctionEnd