elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 ... 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [30] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 ... 58 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 480,237 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #290 en: 11 Septiembre 2013, 10:22 am »

Validar la sintaxis de un RegEx

Código
  1.    #Region " Validate RegEx "
  2.  
  3.       ' [ Validate RegEx Function ]
  4.       '
  5.       ' //By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       ' MsgBox(Validate_RegEx("\"))  ' Result: False
  9.       ' MsgBox(Validate_RegEx("\\")) ' Result: True  
  10.  
  11.    Private Function Validate_RegEx(Pattern As String) As Boolean
  12.  
  13.        Dim temp_RegEx As System.Text.RegularExpressions.Regex
  14.  
  15.        Try
  16.            temp_RegEx = New System.Text.RegularExpressions.Regex(Pattern)
  17.            Return True
  18.        Catch
  19.            Return False
  20.        Finally
  21.            temp_RegEx = Nothing
  22.        End Try
  23.  
  24.    End Function
  25.  
  26.    #End Region


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #291 en: 11 Septiembre 2013, 18:22 pm »

 Resalta los colores de las coincidencias encontradas de una expresión regular en el contenido de un RichTextBox.

Código
  1.  
  2.    #Region " Highlight RegEx In RichTextBox "
  3.  
  4.       ' [ Highlight RegEx In RichTextBox Function ]
  5.       '
  6.       ' //By Elektro H@cker
  7.       '
  8.       ' Examples :
  9.       '
  10.       ' RichTextBox1.Text = String.Format("{0}{1}{0}{1}{0}{1}", "Hello World!", vbNewLine)
  11.       ' Match_RegEx_In_RichTextBox(RichTextBox1, "Hello (World)", 0, Color.Red) ' Colored Result: "Hello World"
  12.       ' Match_RegEx_In_RichTextBox(RichTextBox1, "Hello (World)", 1, Color.Red) ' Colored Result: "World"
  13.  
  14.    Private Sub Highlight_RegEx_In_RichTextBox(ByVal richtextbox As RichTextBox, _
  15.                                           ByVal regex_pattern As String, _
  16.                                           ByVal regex_group As Integer, _
  17.                                           ByVal color As Color)
  18.  
  19.        Dim Matches = Regex.Match(richtextbox.Text, regex_pattern)
  20.  
  21.        Do While Matches.Success
  22.  
  23.            richtextbox.Select(Matches.Groups(regex_group).Index, Matches.Groups(regex_group).Length)
  24.            RichTextBox1.SelectionColor = color
  25.            Matches = Matches.NextMatch()
  26.  
  27.        Loop
  28.  
  29.        richtextbox.Select(richtextbox.TextLength, 0) ' Reset selection
  30.  
  31.        Matches = Nothing
  32.  
  33.    End Sub
  34.  
  35.    #End Region
  36.  
  37.  


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #292 en: 13 Septiembre 2013, 22:11 pm »



· Obtiene el identificador de usuario (SID) de un usuario

Código
  1. #Region " Username To SID "
  2.  
  3.    ' [ Username To SID ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' MsgBox(Username_To_SID("Administrador")) ' Result: S-1-5-21-3344876933-2114507426-1248549232-500
  9.  
  10.    Private Function Username_To_SID(ByVal Username As String) As String
  11.  
  12.        Dim SID As String = New System.Security.Principal.NTAccount(Username). _
  13.                                       Translate(GetType(System.Security.Principal.SecurityIdentifier)).Value
  14.  
  15.        Return SID
  16.  
  17.    End Function
  18.  
  19. #End Region





· Obtiene la carpeta del perfil de usuario de un usuario.

Código
  1. #Region " Username To ProfilePath "
  2.  
  3.    ' [ Username To ProfilePath ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' MsgBox(Username_To_ProfilePath("Administrador")) ' Result: C:\Users\Administrador
  9.  
  10.    Private Function Username_To_ProfilePath(ByVal Username As String) As String
  11.  
  12.        Dim SID As String = _
  13.        New System.Security.Principal.NTAccount(Username). _
  14.        Translate(GetType(System.Security.Principal.SecurityIdentifier)).Value
  15.  
  16.        Return My.Computer.Registry.GetValue( _
  17.               "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & SID, _
  18.               "ProfileImagePath", _
  19.               "Unknown directory")
  20.  
  21.    End Function
  22.  
  23. #End Region






· Obtiene el nombre de usuario de un identificador de usuario (SID)

Código
  1. #Region " SID To Username "
  2.  
  3.    ' [ SID To Username ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' MsgBox(SID_To_Username("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: Administrador
  9.  
  10.    Private Function SID_To_UUsername(ByVal SID As String) As String
  11.  
  12.        Dim DomainName As String = New System.Security.Principal.SecurityIdentifier(SID). _
  13.                                       Translate(GetType(System.Security.Principal.NTAccount)).Value
  14.  
  15.        Return DomainName.Substring(DomainName.IndexOf("\") + 1)
  16.  
  17.    End Function
  18.  
  19. #End Region





· Obtiene la carpeta del perfil de un usuario mediante un identificador de usuario (SID)

Código
  1. #Region " SID To ProfilePath "
  2.  
  3.    ' [ SID To ProfilePath ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' MsgBox(SID_To_ProfilePath("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: "C:\Users\Administrador"
  9.  
  10.    Private Function SID_To_ProfilePath(ByVal SID As String) As String
  11.  
  12.        Return My.Computer.Registry.GetValue( _
  13.               "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & SID, _
  14.               "ProfileImagePath", _
  15.               "Unknown directory")
  16.  
  17.    End Function
  18.  
  19. #End Region
« Última modificación: 14 Septiembre 2013, 05:43 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #293 en: 14 Septiembre 2013, 05:42 am »

· Colorear los items de un ListBox.





Código
  1. #Region " [ListBox] Colorize Items "
  2.  
  3.  
  4.  
  5. ' [ [ListBox] Colorize Items ]
  6. '
  7. ' // By Elektro H@cker
  8. '
  9. ' Examples :
  10. '
  11. ' Set Drawmode to "OwnerDrawFixed" to make this work.
  12. ' ListBox1.DrawMode = DrawMode.OwnerDrawFixed
  13. '
  14. ' Colorize only selected item:
  15. ' Colorize_Item(ListBox1, Colorize_ListBox_Items.Selected, Brushes.YellowGreen)
  16. '
  17. ' Colorize all Non-Selected items
  18. ' Colorize_Item(ListBox1, Colorize_ListBox_Items.Non_Selected, Brushes.Red)
  19. '
  20. ' Colorize all items:
  21. ' Colorize_Item(ListBox1, Colorize_ListBox_Items.All, Brushes.Yellow)
  22. '
  23. ' Colorize any item:
  24. ' Colorize_Item(ListBox1, Colorize_ListBox_Items.None, Nothing)
  25. '
  26. ' Colorize specific items:
  27. ' Colorize_Item(ListBox1, {0, (ListBox1.Items.Count \ 2), (ListBox1.Items.Count - 1)}, Brushes.HotPink)
  28.  
  29.  
  30.  
  31.    ' Stores the brush color to paint
  32.    Dim ListBox_Color As Brush = Brushes.AliceBlue
  33.  
  34.    Private Enum Colorize_ListBox_Items As Short
  35.        Selected = 0
  36.        Non_Selected = 1
  37.        All = 2
  38.        None = 3
  39.    End Enum
  40.  
  41.    Private Sub Colorize_Item(ByVal ListBox As ListBox, _
  42.                              ByVal Items As Colorize_ListBox_Items, _
  43.                              ByVal Brush_Color As Brush)
  44.  
  45.        ' Stores the Enum value
  46.        ListBox.Tag = Items.ToString
  47.  
  48.        ' Stores the brush color
  49.        ListBox_Color = Brush_Color
  50.  
  51.        ListBox.Invalidate() ' Refresh changes
  52.  
  53.    End Sub
  54.  
  55.    Private Sub Colorize_Item(ByVal ListBox As ListBox, _
  56.                              ByVal Items As Integer(), _
  57.                              ByVal Brush_Color As Brush)
  58.  
  59.        ' Stores the index items
  60.        ListBox.Tag = String.Join(ChrW(Keys.Space), Items)
  61.  
  62.        ' Stores the brush color
  63.        ListBox_Color = Brush_Color
  64.  
  65.        ListBox.Invalidate() ' Refresh changes
  66.  
  67.    End Sub
  68.  
  69.    Private Sub ListBox_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) _
  70.    Handles ListBox1.DrawItem
  71.  
  72.        e.DrawBackground()
  73.  
  74.        Select Case sender.tag
  75.  
  76.            Case Colorize_ListBox_Items.Selected.ToString ' Colorize Selected Items
  77.  
  78.                If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  79.                    e.Graphics.FillRectangle(ListBox_Color, e.Bounds)
  80.                End If
  81.  
  82.            Case Colorize_ListBox_Items.Non_Selected.ToString ' Colorize Non-Selected Items
  83.  
  84.                If (e.State And DrawItemState.Selected) = DrawItemState.None Then
  85.                    e.Graphics.FillRectangle(ListBox_Color, e.Bounds)
  86.                End If
  87.  
  88.            Case Colorize_ListBox_Items.All.ToString ' Colorize all
  89.  
  90.                e.Graphics.FillRectangle(ListBox_Color, e.Bounds)
  91.  
  92.            Case Colorize_ListBox_Items.None.ToString ' Colorize none
  93.  
  94.                Dim DefaultColor As SolidBrush = New SolidBrush(ListBox.DefaultBackColor)
  95.                e.Graphics.FillRectangle(DefaultColor, e.Bounds)
  96.                DefaultColor.Dispose()
  97.  
  98.            Case Else ' Colorize at specific index
  99.  
  100.                If Not String.IsNullOrEmpty(sender.tag) _
  101.                AndAlso sender.tag.ToString.Split.Contains(e.Index.ToString) Then
  102.  
  103.                    e.Graphics.FillRectangle(ListBox_Color, e.Bounds)
  104.  
  105.                End If
  106.  
  107.        End Select
  108.  
  109.        Using b As New SolidBrush(e.ForeColor)
  110.            e.Graphics.DrawString(ListBox1.GetItemText(ListBox1.Items(e.Index)), e.Font, b, e.Bounds)
  111.        End Using
  112.  
  113.        e.DrawFocusRectangle()
  114.  
  115.    End Sub
  116.  
  117. #End Region
« Última modificación: 14 Septiembre 2013, 05:44 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #294 en: 16 Septiembre 2013, 08:40 am »

· Una nueva versión de mi FileInfo personalizado, para obtener información sobre un archivo.

Código
  1.    Public Class InfoFile
  2.  
  3. #Region " InfoFile "
  4.  
  5.        ' [ InfoFile ]
  6.        '
  7.        ' // By Elektro H@cker
  8.        '
  9.        ' Examples:
  10.        '
  11.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Name)) ' Result: Test
  12.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Extension_Without_Dot)) ' Result: txt
  13.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileName)) ' Result: Test.txt
  14.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Directory)) ' Result: C:\
  15.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.DriveRoot)) ' Result: C:\
  16.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.DriveLetter)) ' Result: C
  17.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FullName)) ' Result: C:\Test.txt
  18.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.ShortName)) ' Result: Test.txt
  19.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.ShortPath)) ' Result: C:\Test.txt
  20.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Name_Length)) ' Result: 8
  21.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Extension_Without_Dot_Length)) ' Result: 3
  22.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileName_Length)) ' Result: 8
  23.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Directory_Length)) ' Result: 3
  24.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FullName_Length)) ' Result: 11
  25.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileSize_Byte)) ' Result: 5.127.975
  26.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileSize_KB)) ' Result: 5.007.79
  27.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileSize_MB)) ' Result: 4,89
  28.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileSize_GB)) ' Result: 0,00
  29.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileSize_TB)) ' Result: 0,00
  30.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.FileVersion)) ' Result: ""
  31.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Attributes_Enum)) ' Result: 8224
  32.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Attributes_String)) ' Result: Archive, NotContentIndexed
  33.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.CreationTime)) ' Result: 16/09/2012  8:28:17
  34.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.LastAccessTime)) ' Result: 16/09/2012 10:51:17
  35.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.LastModifyTime)) ' Result: 16/09/2012 10:51:17
  36.        ' MsgBox(InfoFile.Get_Info("C:\Test.txt", InfoFile.Info.Has_Extension)) ' Result: True
  37.  
  38.        Public Enum Info
  39.  
  40.            Name                  ' Filename without extension
  41.            Extension_With_Dot    ' File-Extension (with dot included)
  42.            Extension_Without_Dot ' File-Extension (without dot)
  43.            FileName              ' Filename.extension
  44.            Directory             ' Directory name
  45.            FullName              ' Directory path + Filename
  46.  
  47.            DriveRoot             ' Drive letter
  48.            DriveLetter           ' Drive letter (only 1 character)
  49.  
  50.            ShortName ' DOS8.3 Filename
  51.            ShortPath ' DOS8.3 Path Name
  52.  
  53.            Name_Length                  ' Length of Filename without extension
  54.            Extension_With_Dot_Length    ' Length of File-Extension (with dot included)
  55.            Extension_Without_Dot_Length ' Length of File-Extension (without dot)
  56.            FileName_Length              ' Length of Filename.extension
  57.            Directory_Length             ' Length of Directory name
  58.            FullName_Length              ' Length of Directory path + Filename
  59.  
  60.            FileSize_Byte ' Size in Bytes
  61.            FileSize_KB   ' Size in KiloBytes
  62.            FileSize_MB   ' Size in MegaBytes
  63.            FileSize_GB   ' Size in GigaBytes
  64.            FileSize_TB   ' Size in TeraBytes
  65.  
  66.            FileVersion ' Version for DLL or EXE files
  67.  
  68.            Attributes_Enum   ' Attributes as numbers
  69.            Attributes_String ' Attributes as descriptions
  70.  
  71.            CreationTime   ' Date Creation time
  72.            LastAccessTime ' Date Last Access time
  73.            LastModifyTime ' Date Last Modify time
  74.  
  75.            Has_Extension  ' Checks if file have a file-extension.
  76.  
  77.        End Enum
  78.  
  79.        Public Shared Function Get_Info(ByVal File As String, ByVal Information As Info) As String
  80.  
  81.            Dim File_Info = My.Computer.FileSystem.GetFileInfo(File)
  82.  
  83.            Select Case Information
  84.  
  85.                Case Info.Name : Return File_Info.Name.Substring(0, File_Info.Name.LastIndexOf("."))
  86.                Case Info.Extension_With_Dot : Return File_Info.Extension
  87.                Case Info.Extension_Without_Dot : Return File_Info.Extension.Split(".").Last
  88.                Case Info.FileName : Return File_Info.Name
  89.                Case Info.Directory : Return File_Info.DirectoryName
  90.                Case Info.DriveRoot : Return File_Info.Directory.Root.ToString
  91.                Case Info.DriveLetter : Return File_Info.Directory.Root.ToString.Substring(0, 1)
  92.                Case Info.FullName : Return File_Info.FullName
  93.                Case Info.ShortName : Return CreateObject("Scripting.FileSystemObject").GetFile(File).ShortName
  94.                Case Info.ShortPath : Return CreateObject("Scripting.FileSystemObject").GetFile(File).ShortPath
  95.                Case Info.Name_Length : Return File_Info.Name.Length
  96.                Case Info.Extension_With_Dot_Length : Return File_Info.Extension.Length
  97.                Case Info.Extension_Without_Dot_Length : Return File_Info.Extension.Split(".").Last.Length
  98.                Case Info.FileName_Length : Return File_Info.Name.Length
  99.                Case Info.Directory_Length : Return File_Info.DirectoryName.Length
  100.                Case Info.FullName_Length : Return File_Info.FullName.Length
  101.                Case Info.FileSize_Byte : Return Convert.ToDouble(File_Info.Length).ToString("n0")
  102.                Case Info.FileSize_KB : Return (Convert.ToDouble(File_Info.Length) / 1024L).ToString("n2")
  103.                Case Info.FileSize_MB : Return (Convert.ToDouble(File_Info.Length) / 1024L ^ 2).ToString("n2")
  104.                Case Info.FileSize_GB : Return (Convert.ToDouble(File_Info.Length) / 1024L ^ 3).ToString("n2")
  105.                Case Info.FileSize_TB : Return (Convert.ToDouble(File_Info.Length) / 1024L ^ 4).ToString("n2")
  106.                Case Info.FileVersion : Return CreateObject("Scripting.FileSystemObject").GetFileVersion(File)
  107.                Case Info.Attributes_Enum : Return File_Info.Attributes
  108.                Case Info.Attributes_String : Return File_Info.Attributes.ToString
  109.                Case Info.CreationTime : Return File_Info.CreationTime
  110.                Case Info.LastAccessTime : Return File_Info.LastAccessTime
  111.                Case Info.LastModifyTime : Return File_Info.LastWriteTime
  112.                Case Info.Has_Extension : Return IO.Path.HasExtension(File)
  113.  
  114.                Case Else : Return String.Empty
  115.  
  116.            End Select
  117.  
  118.        End Function
  119.  
  120. #End Region
  121.  
  122.    End Class





· Lo mismo de arriba pero para directorios:

Código
  1. Public Class InfoDir
  2.  
  3. #Region " InfoDir "
  4.  
  5.    ' [ InfoDir ]
  6.    '
  7.    ' // By Elektro H@cker
  8.    '
  9.    ' Examples:
  10.    '
  11.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.Name)) ' Result: Test
  12.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.Parent)) ' Result: Test Parent
  13.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FullName)) ' Result: C:\Test Parent\Test
  14.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.DriveRoot)) ' Result: C:\
  15.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.DriveLetter)) ' Result: C
  16.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.Name_Length)) ' Result: 4
  17.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FullName_Length)) ' Result: 19
  18.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.Attributes_Enum)) ' Result: 8208
  19.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.Attributes_String)) ' Result: Directory, NotContentIndexed
  20.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.CreationTime)) ' Result: 16/09/2012  8:28:17
  21.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.LastAccessTime)) ' Result: 16/09/2012 10:51:17
  22.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.LastModifyTime)) ' Result: 16/09/2012 10:51:17
  23.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FileSize_Byte)) ' Result: 5.127.975
  24.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FileSize_KB)) ' Result: 5.007.79
  25.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FileSize_MB)) ' Result: 4,89
  26.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FileSize_GB)) ' Result: 0,00
  27.    ' MsgBox(InfoDir.Get_Info("C:\Test Parent\Test", InfoDir.Info.FileSize_TB)) ' Result: 0,00
  28.  
  29.    Public Enum Info
  30.  
  31.        Name                  ' Folder name
  32.        FullName              ' Directory path
  33.        Parent                ' Parent directory
  34.  
  35.        DriveRoot             ' Drive letter
  36.        DriveLetter           ' Drive letter (only 1 character)
  37.  
  38.        Name_Length                  ' Length of directory name
  39.        FullName_Length              ' Length of full directory path
  40.  
  41.        FileSize_Byte ' Size in Bytes     (including subfolders)
  42.        FileSize_KB   ' Size in KiloBytes (including subfolders)
  43.        FileSize_MB   ' Size in MegaBytes (including subfolders)
  44.        FileSize_GB   ' Size in GigaBytes (including subfolders)
  45.        FileSize_TB   ' Size in TeraBytes (including subfolders)
  46.  
  47.        Attributes_Enum   ' Attributes as numbers
  48.        Attributes_String ' Attributes as descriptions
  49.  
  50.        CreationTime   ' Date Creation time
  51.        LastAccessTime ' Date Last Access time
  52.        LastModifyTime ' Date Last Modify time
  53.  
  54.    End Enum
  55.  
  56.    Public Shared Function Get_Info(ByVal Dir As String, ByVal Information As Info) As String
  57.  
  58.        Dim Dir_Info = My.Computer.FileSystem.GetDirectoryInfo(Dir)
  59.  
  60.        Select Case Information
  61.  
  62.            Case Info.Name : Return Dir_Info.Name
  63.            Case Info.FullName : Return Dir_Info.FullName
  64.            Case Info.Parent : Return Dir_Info.Parent.ToString
  65.            Case Info.DriveRoot : Return Dir_Info.Root.ToString
  66.            Case Info.DriveLetter : Return Dir_Info.Root.ToString.Substring(0, 1)
  67.            Case Info.Name_Length : Return Dir_Info.Name.Length
  68.            Case Info.FullName_Length : Return Dir_Info.FullName.Length
  69.            Case Info.FileSize_Byte : Return Convert.ToDouble(Get_Directory_Size(Dir_Info)).ToString("n0")
  70.            Case Info.FileSize_KB : Return (Convert.ToDouble(Get_Directory_Size(Dir_Info)) / 1024L).ToString("n2")
  71.            Case Info.FileSize_MB : Return (Convert.ToDouble(Get_Directory_Size(Dir_Info)) / 1024L ^ 2).ToString("n2")
  72.            Case Info.FileSize_GB : Return (Convert.ToDouble(Get_Directory_Size(Dir_Info)) / 1024L ^ 3).ToString("n2")
  73.            Case Info.FileSize_TB : Return (Convert.ToDouble(Get_Directory_Size(Dir_Info)) / 1024L ^ 4).ToString("n2")
  74.            Case Info.Attributes_Enum : Return Dir_Info.Attributes
  75.            Case Info.Attributes_String : Return Dir_Info.Attributes.ToString
  76.            Case Info.CreationTime : Return Dir_Info.CreationTime
  77.            Case Info.LastAccessTime : Return Dir_Info.LastAccessTime
  78.            Case Info.LastModifyTime : Return Dir_Info.LastWriteTime
  79.  
  80.            Case Else : Return String.Empty
  81.  
  82.        End Select
  83.  
  84.    End Function
  85.  
  86.    Private Shared Function Get_Directory_Size(Directory As IO.DirectoryInfo) As Long
  87.        Try
  88.            Dim Dir_Total_Size As Long = Directory.EnumerateFiles().Sum(Function(file) file.Length)
  89.            Dir_Total_Size += Directory.EnumerateDirectories().Sum(Function(dir) Get_Directory_Size(dir))
  90.            Return Dir_Total_Size
  91.        Catch
  92.        End Try
  93.        Return -1
  94.    End Function
  95.  
  96. #End Region
  97.  
  98. End Class





Convierte bytes a otra unidad:

Código
  1. #Region " Convert Bytes Function "
  2.  
  3.    ' [ Convert Bytes Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(String.Format("{0} KB", Byte_To_Size(5127975, xByte.kilobyte, 2))) ' Result: 5007,79 KB
  10.    ' MsgBox(String.Format("{0} MB", Byte_To_Size(5127975, xByte.megabyte, 2))) ' Result: 4,89 MB
  11.    ' MsgBox(String.Format("{0} GB", Byte_To_Size(5127975, xByte.gigabyte, 3))) ' Result: 0,005 GB
  12.    ' MsgBox(String.Format("{0} TB", Byte_To_Size(5127975, xByte.terabyte, 3))) ' Result: 0 TB
  13.    ' MsgBox(String.Format("{0} PB", Byte_To_Size(5127975, xByte.petabyte, 3))) ' Result: 0 PB
  14.  
  15.    Enum xByte As Long
  16.        kilobyte = 1024L
  17.        megabyte = 1024L * kilobyte
  18.        gigabyte = 1024L * megabyte
  19.        terabyte = 1024L * gigabyte
  20.        petabyte = 1024L * terabyte
  21.    End Enum
  22.  
  23.    Private Function Byte_To_Size(ByVal bytes As Long, _
  24.                                  ByVal convertto As xByte, _
  25.                                  Optional ByVal decimals As Integer = 2 _
  26.                                  ) As Double
  27.  
  28.        Return (Convert.ToDouble(bytes) / convertto).ToString("n" & decimals)
  29.  
  30.    End Function
  31.  
  32. #End Region
  33.  
En línea

DarK_FirefoX


Desconectado Desconectado

Mensajes: 1.263


Be the change you wanna see in te world


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #295 en: 16 Septiembre 2013, 19:52 pm »

Este post, parece medio viejito, pero EXCELENTE APORTE. OJALA  LO HUBIERA VISTO ANTES....SAlu2s
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #296 en: 16 Septiembre 2013, 20:20 pm »

Este post, parece medio viejito, pero EXCELENTE APORTE. OJALA  LO HUBIERA VISTO ANTES....SAlu2s

Se agradece, pero es una pena que los .NETeros no estén muy interesados por mis publicaciones en este hilo :P

Un saludo!
En línea

ABDERRAMAH


Desconectado Desconectado

Mensajes: 431


en ocasiones uso goto ¬¬


Ver Perfil WWW
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #297 en: 17 Septiembre 2013, 02:59 am »

Pues yo echo mano de este hilo de vez en cuando, hay cosas muy útiles.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #298 en: 17 Septiembre 2013, 19:52 pm »

Pues yo echo mano de este hilo de vez en cuando, hay cosas muy útiles.

se agradece también!





·  Devuelve la conversión de bytes a la unidad de tamaño más aproximada

Por ejemplo, si le pasamos "60877579" bytes, nos devuelve este string: "58,06 MB"

Código
  1.  #Region " Round Bytes "
  2.  
  3.    ' [ Round Bytes Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Round_Bytes(1023))             ' Result: 1.023 Bytes
  10.    ' MsgBox(Round_Bytes(80060, 1))         ' Result: 78,2 KB
  11.    ' MsgBox(Round_Bytes(60877579))         ' Result: 58,06 MB
  12.    ' MsgBox(Round_Bytes(4485888579))       ' Result: 4,18 GB
  13.    ' MsgBox(Round_Bytes(20855564677579))   ' Result: 18,97 TB
  14.    ' MsgBox(Round_Bytes(990855564677579))  ' Result: 901,18 PB
  15.    ' MsgBox(Round_Bytes(1987464809247272)) ' Result: 1,77 PB
  16.  
  17.    Enum xByte As Long
  18.        kilobyte = 1024L
  19.        megabyte = 1024L * kilobyte
  20.        gigabyte = 1024L * megabyte
  21.        terabyte = 1024L * gigabyte
  22.        petabyte = 1024L * terabyte
  23.    End Enum
  24.  
  25.    Private Function Round_Bytes(ByVal bytes As Long, _
  26.                                  Optional ByVal decimals As Integer = 2 _
  27.                                  ) As String
  28.  
  29.        Select Case bytes
  30.  
  31.            Case Is >= xByte.petabyte
  32.                Return String.Format("{0} PB", (Convert.ToDouble(bytes) / xByte.petabyte).ToString("n" & decimals))
  33.  
  34.            Case Is >= xByte.terabyte
  35.                Return String.Format("{0} TB", (Convert.ToDouble(bytes) / xByte.terabyte).ToString("n" & decimals))
  36.  
  37.            Case Is >= xByte.gigabyte
  38.                Return String.Format("{0} GB", (Convert.ToDouble(bytes) / xByte.gigabyte).ToString("n" & decimals))
  39.  
  40.            Case Is >= xByte.megabyte
  41.                Return String.Format("{0} MB", (Convert.ToDouble(bytes) / xByte.megabyte).ToString("n" & decimals))
  42.  
  43.            Case Is >= xByte.kilobyte
  44.                Return String.Format("{0} KB", (Convert.ToDouble(bytes) / xByte.kilobyte).ToString("n" & decimals))
  45.  
  46.            Case Is >= 0
  47.                Return String.Format("{0} Bytes", Convert.ToDouble(bytes).ToString("n0"))
  48.  
  49.            Case Else
  50.                Return String.Empty
  51.  
  52.        End Select
  53.  
  54.    End Function
  55.  
  56. #End Region
« Última modificación: 17 Septiembre 2013, 20:39 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #299 en: 18 Septiembre 2013, 15:25 pm »

· FileSize Converter

Convierte tamaños de unidades de almacenamiento

Código
  1. #Region " FileSize Converter "
  2.  
  3.    ' [ FileSize Converter Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.        ' MsgBox(String.Format("92928374 bytes = {0} Bytes", FileSize_Converter(92928374, Units.bytes, Units.bytes).ToString("n0"))) ' Result: 92.928.374,00 Bytes
  10.        ' MsgBox(String.Format("92928374 bytes = {0} KB", FileSize_Converter(92928374, Units.bytes, Units.kilobyte).ToString("n2"))) ' Result: 90.750,37 KB
  11.        ' MsgBox(String.Format("92928374 bytes = {0} MB", FileSize_Converter(92928374, Units.bytes, Units.megabyte).ToString("n2"))) ' Result: 88,62 MB
  12.        ' MsgBox(String.Format("50 GB = {0} Bytes", FileSize_Converter(50, Units.gigabyte, Units.bytes).ToString("n2"))) ' Result: 53.687.091.200,00 Bytes
  13.        ' MsgBox(String.Format("50 GB = {0} KB", FileSize_Converter(50, Units.gigabyte, Units.kilobyte).ToString("n2"))) ' Result: 52.428.800,00 KB
  14.        ' MsgBox(String.Format("50 GB = {0} MB", FileSize_Converter(50, Units.gigabyte, Units.megabyte).ToString("n2"))) ' Result: 51,200,00 MB
  15.  
  16.    Enum Units As Long
  17.        bytes = 1L
  18.        kilobyte = 1024L
  19.        megabyte = 1048576L
  20.        gigabyte = 1073741824L
  21.        terabyte = 1099511627776L
  22.        petabyte = 1125899906842624L
  23.    End Enum
  24.  
  25.    Private Function FileSize_Converter(ByVal Size As Long, _
  26.                                  ByVal FromUnit As Units, _
  27.                                  ByVal ToUnit As Units) As Double
  28.  
  29.        Dim bytes As Double = Convert.ToDouble(Size * FromUnit)
  30.        Dim result As Double = 0
  31.  
  32.        If ToUnit < FromUnit Then
  33.  
  34.            Select Case ToUnit
  35.                Case Units.bytes : result = bytes
  36.                Case Units.kilobyte : result = bytes / Units.kilobyte
  37.                Case Units.megabyte : result = bytes / Units.megabyte
  38.                Case Units.gigabyte : result = bytes / Units.gigabyte
  39.                Case Units.terabyte : result = bytes / Units.terabyte
  40.                Case Units.petabyte : result = bytes / Units.petabyte
  41.                Case Else : Return -1
  42.            End Select
  43.  
  44.        ElseIf ToUnit > FromUnit Then
  45.  
  46.            Select Case ToUnit
  47.                Case Units.bytes : result = bytes
  48.                Case Units.kilobyte : result = bytes * Units.kilobyte / Units.kilobyte ^ 2
  49.                Case Units.megabyte : result = bytes * Units.megabyte / Units.megabyte ^ 2
  50.                Case Units.gigabyte : result = bytes * Units.gigabyte / Units.gigabyte ^ 2
  51.                Case Units.terabyte : result = bytes * Units.terabyte / Units.terabyte ^ 2
  52.                Case Units.petabyte : result = bytes * Units.petabyte / Units.petabyte ^ 2
  53.                Case Else : Return -1
  54.            End Select
  55.  
  56.        ElseIf ToUnit = FromUnit Then
  57.  
  58.            result = Size
  59.  
  60.        End If
  61.  
  62.        Return result
  63.  
  64.    End Function
  65.  
  66. #End Region
  67.  
« Última modificación: 18 Septiembre 2013, 15:34 pm por EleKtro H@cker » En línea

Páginas: 1 ... 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [30] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 ... 58 Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines