Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Set Folder Attributes

Set Folder Attributes

Scheduled Pinned Locked Moved C / C++ / MFC
questiontoolshelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    P Gibson
    wrote on last edited by
    #1

    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.

    B 1 Reply Last reply
    0
    • P P Gibson

      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.

      B Offline
      B Offline
      bolivar123
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • B bolivar123

        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

        P Offline
        P Offline
        P Gibson
        wrote on last edited by
        #3

        Thanks very much that will do nicely.

        M 1 Reply Last reply
        0
        • P P Gibson

          Thanks very much that will do nicely.

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups