EvilZone
Programming and Scripting => .NET Framework => : Huntondoom December 27, 2010, 12:41:13 AM
-
Imports System
Imports System.IO
Imports System.Text
Module Module1
Dim Path As String = ""
Dim Command As String = ""
Dim Setted As Boolean = False
Dim A As Boolean = False
Dim C As Boolean = False
Dim H As Boolean = False
Dim N As Boolean = False
Dim R As Boolean = False
Dim S As Boolean = False
Sub Main()
Console.Title = "[File Attribute Editor]"
Dim e As String = ""
For Each Arg As String In Environment.GetCommandLineArgs()
e = e & Arg & " "
Next
e = e.Replace("System.String[]", "")
Console.WriteLine(e)
If e.Contains("-") Then
Auto(e)
Else
Manual()
End If
End Sub
Function Auto(ByVal e As String)
If e.Contains("-A") Then A = True
If e.Contains("-C") Then C = True
If e.Contains("-H") Then H = True
If e.Contains("-S") Then S = True
If e.Contains("-R") Then R = True
If e.Contains("-N") Then N = True
Dim Spil() As String = e.Split("-")
Path = Spil(Spil.GetUpperBound(0))
Path = Replac(Path)
Console.WriteLine(Path)
If File.Exists(Path) Then
Dim At As String = ""
At = " Selected Attributes: " & vbCrLf
If A = True Then At = At & "Archive, "
If C = True Then At = At & "Content, "
If H = True Then At = At & "Hidden, "
If N = True Then At = At & "Normal, "
If S = True Then At = At & "SystemFile, "
If R = True Then At = At & "ReadOnly"
Console.WriteLine(At)
Start()
Else
Console.WriteLine("Invalid Path")
Console.ReadLine()
End If
End Function
Function Manual()
Restart:
Dim At As String
While File.Exists(Path) = False
Console.Clear()
If Path = "Help" Then
Help()
Path = ""
End If
Console.WriteLine("Path?")
Path = Console.ReadLine()
Path = Replac(Path)
Setted = True
End While
Console.WriteLine("Path is Valid")
Console.WriteLine(vbCrLf & "Currnet path: " & Path)
While Setted = True
Command = Console.ReadLine()
Console.WriteLine("")
If Command.Contains("Archive;True") Then A = True
If Command.Contains("Archive;False") Then A = False
If Command.Contains("Content;True") Then C = True
If Command.Contains("Content;False") Then C = False
If Command.Contains("Hide;True") Then H = True
If Command.Contains("Hide;False") Then H = False
If Command.Contains("Normal;True") Then N = True
If Command.Contains("Normal;False") Then N = False
If Command.Contains("ReadOnly;True") Then R = True
If Command.Contains("ReadOnly;False") Then R = False
If Command.Contains("System;True") Then S = True
If Command.Contains("System;False") Then S = False
If Command.Contains("Start") Then Start()
If Command.Contains("Check") Then Check()
If Command.Contains("Help") Then Help()
If Command.Contains("Restart") Then
A = False
C = False
H = False
N = False
S = False
R = False
Path = ""
Setted = False
GoTo Restart
End If
If Not (Command.Contains("Check") Or Command.Contains("Start") Or Command.Contains("Help") Or Command.Contains("Restart")) Then
At = "Selected Attributes: " & vbCrLf
If A = True Then At = At & "Archive, "
If C = True Then At = At & "Content, "
If H = True Then At = At & "Hidden, "
If N = True Then At = At & "Normal, "
If S = True Then At = At & "SystemFile, "
If R = True Then At = At & "ReadOnly"
If At.Length > 25 Then Console.WriteLine(At)
End If
Console.WriteLine("")
End While
End Function
Function Help()
If File.Exists(Path) = False Then
Console.WriteLine(vbCrLf & "Help:")
Console.WriteLine("Path Code:")
Console.WriteLine("@DOC - Gets the Path to MyDocuments")
Console.WriteLine("@PRO - Gets the Path to Program Files")
Console.WriteLine("@APP - Gets the Path to Application Data")
Console.WriteLine("@DES - Gets the Path to Desktop")
Console.WriteLine("@STM - Gets the Path to StartMenu")
Console.WriteLine("@STU - Gets the Path to StartUp")
Console.WriteLine("")
Console.WriteLine("How to Use: @DOC\MyPictures\Test.png")
Else
Console.WriteLine(vbCrLf & "Help: ")
Console.WriteLine(" Archive;[True|False] - Set File Archive (is True when Differs form the Backup)")
Console.WriteLine(" Content;[True|False] - Set File To NotContentIndexed(The File will not be indexed by your PC) when True")
Console.WriteLine(" Hide;[True|False] - Set File to Hidden when True")
Console.WriteLine(" Last;[True|False] - Lets you Change 'Last Accessed'")
Console.WriteLine(" Normal;[True|False] - Set File to Normal when True")
Console.WriteLine(" ReadOnly;[True|False] - Set File to ReadOnly when True")
Console.WriteLine(" System;[True|False] - Set File to SystemFile when True")
Console.WriteLine("")
Console.WriteLine("Check - Checks The file attribute status")
Console.WriteLine("Start - Start the process to set the Attributes")
Console.WriteLine("Restart - Reset everything so you can do it over")
Console.WriteLine()
End If
End Function
Function Replac(ByVal Path As String) As String
Path = Path.Replace("@DOC", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
Path = Path.Replace("@PRO", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles))
Path = Path.Replace("@APP", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
Path = Path.Replace("@DES", Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
Path = Path.Replace("@STM", Environment.GetFolderPath(Environment.SpecialFolder.StartMenu))
Path = Path.Replace("@STU", Environment.GetFolderPath(Environment.SpecialFolder.Startup))
Return Path
End Function
Function Check()
Console.WriteLine("Check Result:")
If (File.GetAttributes(Path) And FileAttributes.Archive) = FileAttributes.Archive Then
Console.WriteLine("File.Archive = True")
Else
Console.WriteLine("File.Archive = False")
End If
If (File.GetAttributes(Path) And FileAttributes.Hidden) = FileAttributes.Hidden Then
Console.WriteLine("File.Hidden = True")
Else
Console.WriteLine("File.Hidden = False")
End If
If (File.GetAttributes(Path) And FileAttributes.Normal) = FileAttributes.Normal Then
Console.WriteLine("File.Normal = True")
Else
Console.WriteLine("File.Normal = False")
End If
If (File.GetAttributes(Path) And FileAttributes.NotContentIndexed) = FileAttributes.NotContentIndexed Then
Console.WriteLine("File.NotContentIndexed = True")
Else
Console.WriteLine("File.NotContentIndexed = False")
End If
If (File.GetAttributes(Path) And FileAttributes.ReadOnly) = FileAttributes.ReadOnly Then
Console.WriteLine("File.ReadOnly = True")
Else
Console.WriteLine("File.ReadOnly = False")
End If
If (File.GetAttributes(Path) And FileAttributes.System) = FileAttributes.System Then
Console.WriteLine("File.SystemFile = True")
Else
Console.WriteLine("File.SystemFile = False")
End If
End Function
Function Start()
If H = False And N = False And S = False And R = False Then
Console.WriteLine("No Attributes are selected!")
Exit Function
End If
Console.WriteLine("Setting Attributes")
Console.WriteLine("Must set these Attributes:")
If A = True Then Console.WriteLine("Archive")
If C = True Then Console.WriteLine("NotContentIndexed")
If H = True Then Console.WriteLine("Hidden")
If N = True Then Console.WriteLine("Normal")
If S = True Then Console.WriteLine("SystemFile")
If R = True Then Console.WriteLine("ReadOnly")
File.SetAttributes(Path, FileAttributes.Normal)
'Set Attributes
If A = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.Archive)
If C = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.NotContentIndexed)
If H = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.Hidden)
If N = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.Normal)
If R = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.ReadOnly)
If S = True Then File.SetAttributes(Path, File.GetAttributes(Path) Or FileAttributes.System)
End Function
End Module
Edit: New Method of Setting Attributes have been used,
Archive and NotContentIndexed are edited
-
cd "%homepath\My Documents\Test" && attrib +h TestFile.txt
am i doin' it rite!?
Nice if it's for learning but, I always thought that goal in making something that already exists is to make it better :P
I'm sure you can do better then this :P
But +1 for the effort. I made somewhat similar thing in Delphi some time ago :)
-
cd "%homepath\My Documents\Test" && attrib +h TestFile.txt
that is the command for CMD
my Console Application doesn't work that way :P
in the beginning just give the path and then type help for more
EDIT(ande): Remember to close your quotes.
EDIT: Have Found a better way of setting Attribute that Require less Line more Results, so I'm going to add the Complete list of Set able Attributes some time soon (Probably Tommorow)
and Thanks Ande