Visual Basic Foro

Programación => Visual Basic 6 => Mensaje iniciado por: lucius en Noviembre 28, 2011, 08:11:13 pm

Título: Saber si archivo tipo imagen existe
Publicado por: lucius en Noviembre 28, 2011, 08:11:13 pm
Quiero cargar una imagen de equiz extencion .bmp . jpg etc atravez del nombre pero el problema esta ahi osea si intento cargar imagen.bmp y el archivo se llama imagen.jpg entonces me tira error.

Actualmente lo hago asi pero hay algun otro metodo o como lo hago correctamente.

Código: [Seleccionar]
Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long

Private Sub Command1_Click()

If CStr(CBool(PathFileExists(App.Path & "\xarchivo.jpg"))) = True Then
   MsgBox "existe xarchivo.jpg"
ElseIf CStr(CBool(PathFileExists(App.Path & "\xarchivo.bmp"))) = True Then
   MsgBox "existe xarchivo.bmp"
ElseIf CStr(CBool(PathFileExists(App.Path & "\xarchivo.gif"))) = True Then
   MsgBox "existe xarchivo.gif"
Else
   MsgBox "no existe ningun archivo del tipo imagen"
End If

End Sub
Título: Re:Saber si archivo tipo imagen existe
Publicado por: seba123neo en Noviembre 29, 2011, 01:35:00 am
ese CStr() no es necesario. hay varias formas GetAttr() o estas:

Como verificar si un archivo existe (http://www.recursosvisualbasic.com.ar/htm/trucos-codigofuente-visual-basic/164-verificar-si-archivo-existe.htm#1)

saludos.
Título: Re:Saber si archivo tipo imagen existe
Publicado por: 79137913 en Noviembre 29, 2011, 08:18:56 am
HOLA!!!

La mas facil (no la mas rapida).

Código: (VB) [Seleccionar]
Private Sub FileExist(Path as string) as boolean
    if Len(dir( Path) ) > 0 then FileExist = True

GRACIAS POR LEER!!!