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

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Api, carpetas y archivos.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Api, carpetas y archivos.  (Leído 3,528 veces)
rembolso

Desconectado Desconectado

Mensajes: 163



Ver Perfil
Api, carpetas y archivos.
« en: 3 Abril 2014, 03:33 am »

hola buenas nochess. estoy tratando de hacer un modulo para  listar archivos y carpetas , actualmente me manejo con FileSystemObject , y con la funcion DIR(), o con los controles de usuarion drive y file, dir listbox. quiero hacer algo diferente , puede ser que existan algunas apis que desconozca , me pueden dar una mano.
 nota : que se muestren carpetas y archivos ocultos y protegidos por el sistema.
tienen algun código por ahi ? graxx


En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: Api, carpetas y archivos.
« Respuesta #1 en: 3 Abril 2014, 03:38 am »

aqui las apis de manejo de archivos de windows

creo que dir es un alias de la api findNextFile, con eso puedes manejar las capetas con más precision y control que con dir


En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
noele1995

Desconectado Desconectado

Mensajes: 137



Ver Perfil
Re: Api, carpetas y archivos.
« Respuesta #2 en: 4 Abril 2014, 19:48 pm »

Apis que necesitas para listar carpetas y archivos:
Código
  1. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  2. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  3. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

Si miras por la web encontraras ejemplos como este...
En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: Api, carpetas y archivos.
« Respuesta #3 en: 5 Abril 2014, 01:36 am »

y mi link? :( por que no está... buhh!!!  :-( yo puse el de msdn
En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Api, carpetas y archivos.
« Respuesta #4 en: 9 Abril 2014, 10:43 am »

HAce ya un tiempo atras cree varias clases una de ellas para tratar la busqueda de archivos:

cls_files.cls
Código
  1. '
  2. '   /////////////////////////////////////////////////////////////
  3. '   // Autor:   BlackZeroX ( Ortega Avila Miguel Angel )       //
  4. '   //                                                         //
  5. '   // Web:     http://InfrAngeluX.Sytes.Net/                  //
  6. '   //                                                         //
  7. '   //    |-> Pueden Distribuir Este codigo siempre y cuando   //
  8. '   // no se eliminen los creditos originales de este codigo   //
  9. '   // No importando que sea modificado/editado o engrandecido //
  10. '   // o achicado, si es en base a este codigo                 //
  11. '   /////////////////////////////////////////////////////////////
  12.  
  13. Option Explicit
  14.  
  15. Private Declare Function lstrcmp Lib "kernel32" Alias "lstrcmpA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
  16. Private Declare Function FindFirstFile& Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName$, lpFindFileData As WIN32_FIND_DATA)
  17. Private Declare Function FindNextFile& Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile&, lpFindFileData As WIN32_FIND_DATA)
  18. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
  19. Private Declare Function FindClose& Lib "kernel32" (ByVal hFindFile&)
  20.  
  21. Const MAX_PATH                              As Integer = 260
  22. Const MAXDWORD                              As Long = &HFFFF
  23. Const INVALID_HANDLE_VALUE                  As Long = -1
  24.  
  25. Private Type FILETIME
  26.    dwLowDateTime                           As Long
  27.    dwHighDateTime                          As Long
  28. End Type
  29.  
  30. Private Type WIN32_FIND_DATA
  31.    dwFileAttributes                        As Long
  32.    ftCreationTime                          As FILETIME
  33.    ftLastAccessTime                        As FILETIME
  34.    ftLastWriteTime                         As FILETIME
  35.    nFileSizeHigh                           As Long
  36.    nFileSizeLow                            As Long
  37.    dwReserved0                             As Long
  38.    dwReserved1                             As Long
  39.    cFileName                               As String * MAX_PATH
  40.    cAlternate                              As String * 14
  41. End Type
  42.  
  43. Event Folder(ByRef PathFolder As String, ByVal Atrributes As VbFileAttribute)
  44. Event File(ByRef NameFile As String, ByRef TypeOfFile As Long, ByVal Atrributes As VbFileAttribute)
  45. Event Begin()
  46. Event Finish()
  47.  
  48. Private Priv_StrDir$, Priv_StrCri$(), Priv_IncFolder As Boolean, Priv_Cancel As Boolean
  49. Private Priv_CriFindInDir As VbFileAttribute, Priv_CriFindInFile  As VbFileAttribute
  50. Private Hwnd_SearchF&(), LS_Index&(0 To 1), BytesNow_#
  51. Private Bool_Run As Byte
  52.  
  53. Public AllowEvents                          As Boolean
  54.  
  55. Private Sub Class_Initialize()
  56.    Priv_IncFolder = True
  57.    AllowEvents = True
  58.    Priv_CriFindInDir = vbDirectory
  59.    Priv_CriFindInFile = vbArchive
  60. End Sub
  61.  
  62. Public Property Get BytesNow#()
  63.    BytesNow# = BytesNow_#
  64. End Property
  65.  
  66. Public Property Get FindInPath() As String
  67.    FindInPath = Priv_StrDir$
  68. End Property
  69.  
  70. Public Property Let FindInPath(ByVal vData$)
  71.    Call Stop_
  72.    Call NormalizePath&(vData$)
  73.    Priv_StrDir$ = vData$
  74. End Property
  75.  
  76.  
  77.  
  78. Public Property Get CriterionFindDir() As VbFileAttribute
  79.    CriterionFindDir = Priv_CriFindInDir
  80. End Property
  81. Public Property Let CriterionFindDir(ByVal vData As VbFileAttribute)
  82.    Call Stop_
  83.    Priv_CriFindInDir = vData Or vbDirectory
  84. End Property
  85.  
  86. Public Property Get CriterionFindFile() As VbFileAttribute
  87.    CriterionFindFile = Priv_CriFindInFile
  88. End Property
  89. Public Property Let CriterionFindFile(ByVal vData As VbFileAttribute)
  90.    Call Stop_
  91.    Priv_CriFindInFile = vData Or vbArchive
  92. End Property
  93.  
  94.  
  95.  
  96. Public Property Get CriterionToFind() As Variant
  97.    CriterionToFind = Priv_StrCri$
  98. End Property
  99.  
  100. Public Property Let CriterionToFind(ByRef vData As Variant)
  101. On Error GoTo Err_
  102. Dim L_Index                             As Long
  103.    Call Stop_
  104.    Erase Priv_StrCri$
  105.    LS_Index&(0) = INVALID_HANDLE_VALUE
  106.    LS_Index&(1) = INVALID_HANDLE_VALUE
  107.    If IsArray(vData) Then
  108.        LS_Index&(0) = LBound(vData)
  109.        LS_Index&(1) = UBound(vData)
  110.        ReDim Priv_StrCri$(LS_Index&(0) To LS_Index&(1))
  111.        For L_Index = LS_Index&(0) To LS_Index&(1)
  112.            Priv_StrCri$(L_Index) = CStr(vData(L_Index))
  113.        Next L_Index
  114.    Else
  115.        LS_Index&(0) = 0
  116.        LS_Index&(0) = 0
  117.        ReDim Priv_StrCri$(0)
  118.        Priv_StrCri$(0) = vData
  119.    End If
  120. Exit Property
  121. Err_:
  122.    Err.Clear
  123. End Property
  124.  
  125. Public Property Get IncludeSubFolders() As Boolean: IncludeSubFolders = Priv_IncFolder: End Property
  126. Public Property Let IncludeSubFolders(ByVal vData As Boolean): Priv_IncFolder = vData: End Property
  127.  
  128. Public Property Get ItsRun() As Boolean:    ItsRun = Bool_Run = 1:      End Property
  129.  
  130. Public Sub Stop_():    Bool_Run = 0: Priv_Cancel = True: End Sub
  131.  
  132. Public Function Start_(Optional StrFindInPath As Variant = "", Optional StrCriterionToFind As Variant = Nothing) As Double
  133.  
  134.    Call Stop_
  135.    BytesNow_# = 0
  136.    If Not StrFindInPath = "" Then FindInPath = StrFindInPath
  137.    If Not IsObject(StrCriterionToFind) Then CriterionToFind = StrCriterionToFind
  138.    If Not (LS_Index&(0) = INVALID_HANDLE_VALUE And LS_Index&(0) = INVALID_HANDLE_VALUE) And Priv_StrDir$ <> "" And CStr(Dir(Priv_StrDir$, vbDirectory)) <> "" Then
  139.        RaiseEvent Begin
  140.        Bool_Run = 1
  141.        Priv_Cancel = False
  142.        Call FindFilesAPI#(Priv_StrDir$, Priv_StrCri$())
  143.        Start_# = BytesNow_#
  144.        Bool_Run = 0
  145.        RaiseEvent Finish
  146.    End If
  147.  
  148. End Function
  149.  
  150. Private Sub FindFilesAPI(ByVal StrPath$, ByRef StrSearch$())
  151. Dim str_NameNow$
  152. Dim Str_NameDir$()
  153. Dim Lng_DirCant&
  154. Dim Lng_DirCount&
  155. Dim LF_Index&
  156. 'Dim Lng_Res&
  157. Dim Hwnd_Search&
  158. Dim WFD                                 As WIN32_FIND_DATA
  159.  
  160.    Lng_DirCount& = 0
  161.    Hwnd_Search& = FindFirstFile&(StrPath$ & "*", WFD)
  162.  
  163.    If Hwnd_Search& <> INVALID_HANDLE_VALUE Then
  164.        RaiseEvent Folder(StrPath$, WFD.dwFileAttributes)
  165.        Do
  166.            If AllowEvents Then DoEvents
  167.            If Priv_Cancel Then Exit Sub
  168.            With WFD
  169.                str_NameNow$ = Left$(.cFileName, InStr(.cFileName, Chr(0)) - 1)
  170.                If (((.dwFileAttributes Or Priv_CriFindInDir) = .dwFileAttributes) And ((.dwFileAttributes And vbDirectory) = vbDirectory)) Then
  171.                    If (str_NameNow$ <> ".") And (str_NameNow$ <> "..") Then
  172.                        ReDim Preserve Str_NameDir$(Lng_DirCount&)
  173.                        Str_NameDir$(Lng_DirCount&) = str_NameNow$
  174.                        Lng_DirCount& = Lng_DirCount& + 1
  175.                    End If
  176.                End If
  177.            End With
  178.        Loop While FindNextFile&(Hwnd_Search&, WFD)
  179.  
  180.        Call FindClose(Hwnd_Search&)
  181.  
  182.        For LF_Index& = LS_Index&(0) To LS_Index&(1)
  183.            Hwnd_Search& = FindFirstFile&(StrPath$ & StrSearch$(LF_Index&), WFD)
  184.            If Hwnd_Search& <> INVALID_HANDLE_VALUE Then
  185.                Do
  186.                    If AllowEvents Then DoEvents
  187.                    If Priv_Cancel Then Exit Sub
  188.                    With WFD
  189.                        str_NameNow$ = Left$(.cFileName, InStr(.cFileName, Chr(0)) - 1)
  190.                        If (((.dwFileAttributes Or Priv_CriFindInFile) = .dwFileAttributes) And ((.dwFileAttributes And vbArchive) = vbArchive)) Then
  191.  
  192.                            If (str_NameNow$ <> ".") And (str_NameNow$ <> "..") Then
  193.                                BytesNow_# = BytesNow_# + ((.nFileSizeHigh& * MAXDWORD&) + .nFileSizeLow&) + 0
  194.                                RaiseEvent File(str_NameNow$, LF_Index&, .dwFileAttributes)
  195.                            End If
  196.                        End If
  197.                    End With
  198.                Loop While FindNextFile&(Hwnd_Search&, WFD)
  199.                Call FindClose(Hwnd_Search&)
  200.            End If
  201.        Next LF_Index
  202.  
  203.        If Lng_DirCount& > 0 And Priv_IncFolder Then
  204.            For Lng_DirCant& = 0 To Lng_DirCount& - 1
  205.                Call FindFilesAPI#(StrPath$ & Str_NameDir$(Lng_DirCant&) & "\", StrSearch$)
  206.            Next
  207.        End If
  208.  
  209.    End If
  210.  
  211. End Sub
  212.  
  213. '   Returns
  214. '   //  0   =   NoPathValid
  215. '   //  1   =   Ok
  216. '   //  2   =   Fixed/Ok
  217. Public Function NormalizePath&(ByRef sData$)
  218.  
  219.    If Strings.Len(sData$) > 1 Then
  220.        sData$ = Strings.Replace(sData$, "/", "\")
  221.        If Not Strings.Right$(sData$, 1) = "\" Then
  222.            sData$ = sData$ & "\"
  223.            NormalizePath& = 2
  224.        Else
  225.            NormalizePath& = 1
  226.        End If
  227.    Else
  228.        NormalizePath& = 0
  229.    End If
  230.  
  231. End Function
  232.  

Ejemplo:

Código
  1. Option Explicit
  2.  
  3. Private WithEvents ClsScanDisk          As cls_files
  4. Private ThisPath$
  5. Private CountFiles&
  6.  
  7. Private Sub ClsScanDisk_Begin()
  8.    ThisPath$ = ClsScanDisk.FindInPath
  9.    CountFiles& = 0
  10.    Caption = "ScanDisk ha Encontrado: "
  11. End Sub
  12.  
  13. Private Sub ClsScanDisk_File(NameFile As String, TypeOfFile As Long, ByVal Atrributes As Long)
  14.    CountFiles& = CountFiles& + 1
  15.    Caption = "ScanDisk ha Encontrado: " & CountFiles&
  16.    Debug.Print ThisPath$ & NameFile
  17.    Debug.Print vbTab & "Criterio:"; ClsScanDisk.CriterionToFind(TypeOfFile),
  18.    Debug.Print "Atributos:"; Atrributes
  19. End Sub
  20.  
  21. Private Sub ClsScanDisk_Finish()
  22.    Caption = "ScanDisk ha Encontrado: " & CountFiles& & " -> Finalizado."
  23. End Sub
  24.  
  25. Private Sub ClsScanDisk_Folder(PathFolder As String, ByVal Atrributes As Long)
  26.    ThisPath$ = PathFolder
  27. End Sub
  28.  
  29.  
  30. Private Sub Form_Load()
  31.    If ClsScanDisk Is Nothing Then Set ClsScanDisk = New cls_files
  32.    With ClsScanDisk
  33.        If .ItsRun Then .Stop_
  34.        .CriterionToFind = Split("*.mp3,*.wma,*.avi,*.mid,*.mid", ",")
  35.        '.CriterionFindDir = vbReadOnly                  '   //  Solo directorios de Solo lectura.
  36.        '.CriterionFindFile = vbHidden Or vbReadOnly     '  //  Solo archivos ocultos.
  37.        .FindInPath = "c:\"
  38.        .AllowEvents = True
  39.        Call .Start_
  40.    End With
  41. End Sub
  42.  

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Copiado de archivos y carpetas
Programación Visual Basic
Gorky 3 3,160 Último mensaje 21 Noviembre 2007, 17:03 pm
por cassiani
CARPETAS Y ARCHIVOS DE UN USUARIO DE 4shared.com
Foro Libre
cj3666 3 15,317 Último mensaje 9 Agosto 2014, 18:56 pm
por bonampi
[Bat] Copiar Carpetas y Archivos USB
Scripting
KZN 3 6,535 Último mensaje 10 Marzo 2014, 14:47 pm
por Eleкtro
Crear inyecto de archivos en carpetas diferentes
Dudas Generales
chapalee 2 1,786 Último mensaje 26 Marzo 2023, 05:39 am
por chapalee
W7: ¿Modo fácil de que las carpetas muestren archivos ordenados por fecha?
Windows
Tachikomaia 1 1,326 Último mensaje 8 Enero 2024, 18:41 pm
por Songoku
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines