Archive: Trouble with file attributes


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.

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

Well, I might've solved problem 2 like so:

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

#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


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