Click to See Complete Forum and Search --> : Abnormal Behaviour in Setting File Attribute


nbaztec
July 24th, 2009, 08:54 AM
I was creating a win32 form in Borland C++ Builder 6.0 which required me to Change the attributes of some files.

Program Algorithm

1) Copy a Background and/or Icon based on Users choice to a Location pointed by user.
2) User clicks a Button to Change the Background and/or Icon to Hidden.


String F_Background; //Path to Background File after copying
String F_Icon; //Path to Icon File after copying

String BackPath="\""+F_Background+"\"";
String IconPath="\""+F_Icon+"\"";


CopyFile(FixPath(BackPath).c_str(),FixPath(FoldPath).c_str(),false); //To Copy Background
CopyFile(FixPath(IconPath).c_str(),FixPath(FoldPath).c_str(),false); //To Copy Icon


//FoldPath is a String defined earlier to pass the argument of New File Name; Functions as required
//FixPath is a Custom Function to Fix Paths so as to Parse them in certain functions
//Eg. convert C:\Windows\ETC to C:\\Windows\\ETC
//BackPath



//To Change Attributes
SetFileAttributes(F_Background.c_str(),FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
SetFileAttributes(F_Icon.c_str(),FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);




Function SetFileAttributes As in BCB HELP:

BOOL SetFileAttributes(

LPCTSTR lpFileName, // address of filename
DWORD dwFileAttributes // address of attributes to set
);


The only problem is the program copies the file to the Directory pointed by user and I successfully get the Paths after the files have been copied but the Program doesn't hide them.
Also the Functions return 1 i.e. non-zero for success..

The Files are Hidden in Following Peculiar Cases

-If I click on the Button again (Which performs the same operation again) the files are hidden.

-Also if I copy and change attributes once (Which doesn't hide the files) then close the program
then try to perform the same operation again on the same chosen file(s) and on the Same
Folder(Where the files are already copied but not hidden) it hides them in one go.

-It also hides any Background/Icon in any other chosen Folder, which were processed(copied and hidden) successfully by it in 2 tries..

Any help is Greatly appreciated.
Thanks,
nbaztec