DevAdmin Blog

Blog di Ermanno Goletto (Microsoft MVP Directory Services - MCITP - MCTS - MCSA - MCP)
posts - 887, comments - 447, trackbacks - 13

My Links

News

Avatar

Curriculum Vitae

Visualizza il profilo di Ermanno Goletto su LinkedIn


Il contenuto di questo blog e di ciascun post viene fornito “così come é”, senza garanzie, e non conferisce alcun diritto. Questo blog riporta il mio personale pensiero che non riflette necessariamente il pensiero del mio datore di lavoro.

Logo Creative Commons Deed


Logo SysAdmin.it SysAdmin.it Staff


Logo TechNet Forum TechNet Italia @ForumTechNetIt Follow TechNet Forum on Twitter


Logo MVP


Ermanno Goletto Follow ermannog on Twitter

Article Categories

Archives

Post Categories

Blogs

Friends

Knowledge Base

MVP Sites

Resources

Impostare l'attributo di un file tramite script

In DOS esiste il pratico comando ATTRIB:
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/it/library/ServerHelp/56202570-64a8-424b-8a11-09f5b8584cab.mspx?mfr=true

In WSH invece è possibile ricorrere ad un codice del tipo che imposta l'attributo Archive per un singolo file o per tutti i file in una directory e relative subdirectory:

WSH.echo ToggleArchiveBit("F:\test.txt")
SetArchiveBit("F:\Test")

Function ToggleArchiveBit(filePath)
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFile = objFSO.GetFile(filePath)

 If objFile.Attributes And 32 then
      objFile.Attributes = objFile.Attributes XOR 32
      ToggleArchiveBit = "Archive bit is cleared."
 Else
      objFile.Attributes = objFile.Attributes XOR 32
      ToggleArchiveBit = "Archive bit is set."
 End If
End Function

Function SetArchiveBit(Path)
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFolder = objFSO.GetFolder(Path)
 Set colSubfolders = objFolder.Subfolders
 For Each objSubfolder in colSubfolders
   SetArchiveBit(objSubfolder.Path)
 Next

 Set colFiles = objFolder.Files
 For Each objFile in colFiles
  If Not objFile.Attributes And 32 then
   objFile.Attributes = objFile.Attributes XOR 32
  End If
  Next
End Function

Ovviamente il codice è adattabile anche ad altri attributi per maggiori info:
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_elex.mspx
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_owhk.mspx
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_brxn.mspx
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_jozd.mspx

Print | posted on Wednesday, July 12, 2006 12:57 PM | Filed Under [ Links Code, Snippets & Scripts IT ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 6 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET