Base myvar="102016", how to check if file in dir exists, and retrieve the complete name of file?
Possible without loop file in dir?
all file have a numeric name, but with variable length
Find name of file in dir
-
- PlatinumLounger
- Posts: 4169
- Joined: 26 Apr 2010, 17:36
Find name of file in dir
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 75751
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Find name of file in dir
Code: Select all
Dim myFolder As String
Dim myFile As String
myFolder = "C:\Lavori_VB6\...\...\"
myFile = Dir(myFolder & myVar & ".*")
If myFile = "" Then
MsgBox "File does not exist!"
Else
MsgBox "The complete filename is " & myFile
End If
Regards,
Hans
Hans
-
- PlatinumLounger
- Posts: 4169
- Joined: 26 Apr 2010, 17:36
Re: Find name of file in dir
HansV wrote: ↑28 Nov 2022, 08:14Code: Select all
Dim myFolder As String Dim myFile As String myFolder = "C:\Lavori_VB6\...\...\" myFile = Dir(myFolder & myVar & ".*") If myFile = "" Then MsgBox "File does not exist!" Else MsgBox "The complete filename is " & myFile End If

-
- PlatinumLounger
- Posts: 4169
- Joined: 26 Apr 2010, 17:36
Re: Find name of file in dir
sorry bro...HansV wrote: ↑28 Nov 2022, 08:14Code: Select all
Dim myFolder As String Dim myFile As String myFolder = "C:\Lavori_VB6\...\...\" myFile = Dir(myFolder & myVar & ".*") If myFile = "" Then MsgBox "File does not exist!" Else MsgBox "The complete filename is " & myFile End If
based this code how to rename only all files with namefile.jpeg in namefile.jpg, delete old file , *.jpeg
-
- Administrator
- Posts: 75751
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Find name of file in dir
Code: Select all
Dim myFolder As String
Dim myFile As String
myFolder = "C:\Lavori_VB6\...\...\"
myFile = Dir(myFolder & "*.jpeg")
Do While myFile <> ""
Name myFolder & myFile As myFolder & Replace(myFile, ".jpeg", ".jpg")
myFile = Dir
Loop
Regards,
Hans
Hans
-
- PlatinumLounger
- Posts: 4169
- Joined: 26 Apr 2010, 17:36
Re: Find name of file in dir
bro...sal21 wrote: ↑28 Nov 2022, 08:35HansV wrote: ↑28 Nov 2022, 08:14Code: Select all
Dim myFolder As String Dim myFile As String myFolder = "C:\Lavori_VB6\...\...\" myFile = Dir(myFolder & myVar & ".*") If myFile = "" Then MsgBox "File does not exist!" Else MsgBox "The complete filename is " & myFile End If
![]()
is this correct to use a multi pattern for files in dir:
...
sPATTERN = "*.gif;*.bmp;*.jpg"
sPath = STRPATHIMG
sfile = Dir(sPath & sPATTERN & ".*")
...
-
- Administrator
- Posts: 75751
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Find name of file in dir
No, you can process only one attachment at a time. So you'll have to use one loop for *.gif, one for *.bmp and one for *.gif.
Regards,
Hans
Hans
-
- PlatinumLounger
- Posts: 4169
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 75751
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Find name of file in dir
Yes:
Code: Select all
Dim myFolder As String
Dim myFile As String
dim myExtension As Variant
myFolder = "C:\Lavori_VB6\...\...\"
For Each myExtension in Array("*.gif", "*.jpg", "*.bmp")
myFile = Dir(myFolder & myExtention)
Do While myFile <> ""
' Your code here
...
myFile = Dir
Loop
Next myExtension
Regards,
Hans
Hans