Hola, favor si me podrian decir como puedo hacer para saber si un archivo existe en un determinado directorio.
estuve probando con esta:
Dim Ruta
Ruta= App.Patch & "C:fri.txt"
If Dir(Ruta, vbArchive) = "" Then
msgbox "no existe"
else
msgbox "si existe"
End IF
Estuve testeando hace meses por aqui que habia una sentencia mas o menos que era como: File.existe o algo parecido.
Favor si me podrian decir si..
Spero q esot t ayude ;)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Dim DirArchivo As String
Private Sub Form_Load()
DirArchivo = "C:\texto.txt"
Comprobar (DirArchivo) ' comprobamos q exista ese archivo
End Sub
Public Sub Comprobar(Directorio As String)
On Error Resume Next ' en caso d error continúa
Open Directorio For Input As #1
If Err Then ' error x tanto no existe
MsgBox "El archivo no existe"
Else
MsgBox "El archivo existe"
End If
Close #1
End Sub
Saludos! :)
Ese q probastes esta bien solo q si queres comprobar si "C:\fri.txt" existes tenes q cambiar:
Ruta= App.Patch & "C:fri.txt"
por
Ruta = "C:\fri.txt""
P.D App.Patch no existe lo mas parecido es app.path
ok. gracias.. a todos..
buff q complicaciones. Hazlo así:
archivo = "C:\existe.txt"
existe = Len(Dir$(archivo))
If existe Then
MsgBox "El archivo existe"
Else
MsgBox "El archivo no existe"
End If
Mira este:
Private Sub Form_Load()
On error goto error
GetAttr("C:\Archivo.txt")
MsgBox("El archivo existe")
error:
MsgBox("El archivo no existe")
End Sub
Yo lo ago de estas 2 maneras:
1.
Public Function ArchEx(Ruta As String) As Boolean
On Error GoTo error
GetAttr (Ruta)
ArchEx = True
Exit Function
error:
ArchEx = False
End Function
Para llamar a la funcion asi:
If ArchEx("C:\boot.ini") = True Then
' Lo que quieras tu ;)
End If
2.
Con la api.
Private Declare Function SHFileExists Lib "shell32" Alias "#45" (ByVal szPath As String) As Long
Private Sub Form_Load()
If SHFileExists("C:\Dance.MID") = 0 Then
MsgBox "NO EXISTE"
Else
MsgBox "EXISTE"
End If
End Sub
LA API SOLO VA EN WIN 9x
Salu2
If Dir("C:\Tuarchivo.jpg") <> "" Then
MsgBox "El archivo existe."
Else
MsgBox "El archivo no existe."
End If