Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Changing file attributes

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,30258
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> Changing file attributes
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Changing file attributes - 1/25/2006 1:43:08 AM   
  crazymatt

 

Posts: 287
Score: 0
Joined: 3/4/2005
From:
Status: offline
I've just made a script that changes (switches between archive and hidden attrib) attributes on a file (if the file dont exsist it creates it).


      

Well the script works ok, but i cant seem to keep the old attribute, neither can i set more than one attribute.

I've tried the following code instead of [System.IO.File]::SetAttributes($path, [System.IO.FileAttributes]::Hidden):
[System.IO.File]::SetAttributes($path, [System.IO.File]::GetAttributes($path) -and [System.IO.FileAttributes]::Hidden)
but that gets me an error, so does
[System.IO.File]::SetAttributes($path, [System.IO.FileAttributes]::Archive -and [System.IO.FileAttributes]::Hidden)
and
[System.IO.File]::SetAttributes($path, [System.IO.FileAttributes]::Archive,Hidden
 
Since i dont have a clue how to program .Net or Msh i dont know what im doing wrong or how make it work the way i want. Any help is appricated :D

/CM

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.
 
 
Post #: 1
 
 RE: Changing file attributes - 1/25/2006 4:53:50 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Does this do what you want?


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crazymatt)
 
 
Post #: 2
 
 RE: Changing file attributes - 1/25/2006 7:49:56 PM   
  crazymatt

 

Posts: 287
Score: 0
Joined: 3/4/2005
From:
Status: offline
Nope, that just seems to do what my script does.
And this code "$out | out-file $path" gives me an error. Edit: It only generates an error when the file is hidden.

Both ur and my script just switches between the Archive and Hidden attrib.
I dont want Archive to be removed, so the two modes should be "Archive" or "Archive AND Hidden".
And preferebly i dont want to specify the Archive bit i just want it to add the Hidden flag, not replace the previous one/ones.

So what i want i more or less be able to check the previos flags and then add/remove just the "Hidden" flag.

This line was an effort to do that: [System.IO.File]::SetAttributes($path, [System.IO.File]::GetAttributes($path) -and [System.IO.FileAttributes]::Hidden)
But it dont work :)

< Message edited by crazymatt -- 1/25/2006 8:43:49 PM >


_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Changing file attributes - 1/26/2006 2:36:26 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Hmm...that code works for me. It doesn't do exactly what you wnated because I didn't completely understand the result you wanted, but it does run without erors. I'll try to poke around in it some more. If you get a chance, post the error you are getting.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crazymatt)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> Changing file attributes Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts