Old 11th October 2007, 21:19   #1
Quib
Junior Member
 
Join Date: Aug 2007
Posts: 12
Trouble with file attributes

I have two objectives that I'm having difficulty with:
1) Removing a single attribute flag from a file (I want to remove the archive flag from a set of files, but not change anything else on them).
2) Copy a folder without copying the files/folders within the folder.

For issue 1, ${GetFileAttributes} and SetFileAttributes are proving difficult to work with; should I just make exec calls to attrib.exe? My main concern is efficiency as my utility may be working on 1000+ files at a time.

For issue 2, currently I'm just checking the existence of the folder name I want to copy at the target location and using CreateDirectory. Unfortunately, this means the folder may have differing attribute flags.
code:
SetFileAttributes "$TARGETDIRECTORY$R0" NORMAL
${GetFileAttributes} "$SOURCEDIRECTORY$R0" "ALL" $R3
SetFileAttributes "$TARGETDIRECTORY$R0" $R3


doesn't work because SetFileAttributes doesn't seem to accept a variable as input.

Anyhow, any feedback'd be appreciated and hopefully this post will generate some searchable help on the subject. I couldn't find beans when searching about this type of thing.

QM
Quib is offline   Reply With Quote
Old 12th October 2007, 20:47   #2
Quib
Junior Member
 
Join Date: Aug 2007
Posts: 12
Well, I might've solved problem 2 like so:
code:
System::Call 'kernel32::GetFileAttributes(t "$SOURCEDIRECTORY$R0")i .R8'
System::Call 'kernel32::GetFileAttributes(t "$TARGETDIRECTORY$R0")i .R9'
IntCmp $R8 $R9 Jump_Past_Set
System::Call 'kernel32::SetFileAttributes(t "$TARGETDIRECTORY$R0", i R8)'


The IntCmp jumps past the SetFileAttributes if the attributes are already equal.

Is this acceptable to do? Will I run into issues on various versions of Windows or anything? I only have a 98SE and XP machine to test on.

I haven't gotten to problem 1 yet, but I imagine I'll use System::Call there as well.

QM
Quib is offline   Reply With Quote
Old 12th October 2007, 22:13   #3
CancerFace
Senior Member
 
Join Date: Apr 2006
Posts: 289
Send a message via ICQ to CancerFace
#1: Call GetFileAttributes(A/W) then subtract from the output value FILE_ATTRIBUTE_ARCHIVE with an IntOp, then call SetFileAttributes(A/W) and push the modified attributes.

You will still have to figure out though how to deal with the case that the archive attribute was not set on a file, but you still subtracted FILE_ATTRIBUTE_ARCHIVE from the list of attributes ...

Are the file attributes different between files? If not then you could just check the attributes of one file then set the same (+ or - anything) to the rest of the files in that folder.

CF
CancerFace is offline   Reply With Quote
Old 13th October 2007, 00:30   #4
Quib
Junior Member
 
Join Date: Aug 2007
Posts: 12
Quote:
Originally posted by CancerFace
#1: Call GetFileAttributes(A/W) then subtract from the output value FILE_ATTRIBUTE_ARCHIVE with an IntOp, then call SetFileAttributes(A/W) and push the modified attributes.

...

CF
This is exactly what I wound up doing. I simply check if a file has the archive flag set before subtracting it and jump past if the file doesn't have the flag.

I'll have something to show for this pretty soon. I wrote a file backup/synchronize/archive utility using NSIS and I'm putting it through testing now.

QM
Quib is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump