-3

How can I change an attribute on an existing folder?

I have to make this folder and all files existing in it visible.

C:\Documents and Settings\%USER%\appdata

I found this code:

FileAttributes attributes = File.GetAttributes(@"C:\Documents and Settings\%user%\Dane aplikacji");

attributes = RemoveAttribute(attributes, FileAttributes.Hidden);


private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
    {
        return attributes & ~attributesToRemove;
    }

but it's not working :(

thanks !

BenR
  • 11,296
  • 3
  • 28
  • 47
Icet
  • 678
  • 2
  • 13
  • 31
  • 1
    What's not working about it? Is it throwing an exception (if so, what?)? – Rowland Shaw Oct 10 '14 at 13:19
  • I realise this is not an answer, but why are you trying to un-hide a system folder? If the user wants to see it, then they can do that via the Explorer menu. – Neil Oct 10 '14 at 13:26
  • Did you make an attempt to understand the code you found somewhere? – Jonesopolis Oct 10 '14 at 13:27
  • Not a proper answer, but a hint: is there anything special and/or magical about the variable `attributes`? Does assigning to it have any side effects? – Mike Caron Oct 10 '14 at 14:04

1 Answers1

2

In your code you are just updating the attributes variable but not actually updating the attributes for the file.

You need to use File.SetAttributes('path', attributes)

BenR
  • 11,296
  • 3
  • 28
  • 47