Set Folder Attributes
-
By default on our XP cleints the indexing service for folders is turned off, I want to set a folder and its files to have the indexing turned on, SetFileAttributes would seem to be the way of doing this but there does not seem to be a constant to do this, so what is the reverse of FILE_ATTRIBUTE_NOT_CONTENT_INDEXED ? Or anybody know how to do it in Window Script ? I've had a good search and cannot find anything, any help, as ever, will be much appreciated.
-
By default on our XP cleints the indexing service for folders is turned off, I want to set a folder and its files to have the indexing turned on, SetFileAttributes would seem to be the way of doing this but there does not seem to be a constant to do this, so what is the reverse of FILE_ATTRIBUTE_NOT_CONTENT_INDEXED ? Or anybody know how to do it in Window Script ? I've had a good search and cannot find anything, any help, as ever, will be much appreciated.
This should do the trick:
BOOL ToggleFileAttribute(LPSTR lpstrFileName,DWORD dwToggleAttribute) { DWORD dwFileAttributes = GetFileAttributes(lpstrFileName); DWORD newdwFileAttributes = dwFileAttributes & ~dwToggleAttribute; return SetFileAttribute(lpstrFileName,newdwFileAttributes ); } //To call the function: if (ToggleFileAttribute("c:\\foo.dat",FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) { //Attribute successfully toggled } else { //Attribute toggle failed }
If you want to do this on all the files in a folder and its subfolders, you'll need to write a function that can recursively traverse and toggle the FILE_ATTRIBUTE_NOT_CONTENT_INDEXED bit on each file. -- modified at 8:42 Friday 3rd February, 2006 -
This should do the trick:
BOOL ToggleFileAttribute(LPSTR lpstrFileName,DWORD dwToggleAttribute) { DWORD dwFileAttributes = GetFileAttributes(lpstrFileName); DWORD newdwFileAttributes = dwFileAttributes & ~dwToggleAttribute; return SetFileAttribute(lpstrFileName,newdwFileAttributes ); } //To call the function: if (ToggleFileAttribute("c:\\foo.dat",FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) { //Attribute successfully toggled } else { //Attribute toggle failed }
If you want to do this on all the files in a folder and its subfolders, you'll need to write a function that can recursively traverse and toggle the FILE_ATTRIBUTE_NOT_CONTENT_INDEXED bit on each file. -- modified at 8:42 Friday 3rd February, 2006 -
Don't forget to check the return value of
GetFileAttributes()
. If that fails and you don't check,SetFileAttributes()
will munge the attributes, which is Bad. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy