Hi,
I’m looking for some piece of code to list files in directory but with some filter.
I must verify if I have simile files in directory.
I tried to use the code from but it’s not working like I would like.
I tried get in “listbox” (lstFileList) files contain number from [Numero] field (Numero field is numeric e.g. 0022038).
The name of the file could be a number e.g.: 0022038.doc
or mist COR-1LD-1871-1226-0022038.doc
If they exist, I would like only them, to show in listbox.
If possible only file names without full directory path.
Do you know how build a string with “LIKE” option to do the same?
This is part of code I tried to use to check if files are in directory:
Private Sub Form_Current()
Dim nomefnr, nomefnome, nomefpdf, cartella, Categoria, nomefilenumero, nomefilenome, nomefilepdf As Variant
Dim criteri As String
Dim, MyPath As String
'Prova di verificare il file
cartella = Application.CurrentProject.Path
Categoria = Me!Categoria
MyPath = cartella & "\AD\DOC\" & Categoria & "\"
'''Verifico se ci sono i file nella directory
'Call ListFiles(MyPath, , "WHERE Me!Numero Like "*" & Format(Me!Numero, "0000000") & ".doc", Me.lstFileList)
'Call ListFiles(MyPath, , "*[! 0-9A-Z]*" & Format(Me!Numero, "0000000") & ".doc", Me.lstFileList)
End Sub
Call ListFiles is function from put in Modules.
---
I tried also so to make visible button to open a file (please don’t laugh) but this could be confuse if there are more file with same number. So I will go more in direction of listbox:
'''Verifico se il file con nome uguale al numero esiste
'''Se esiste, rendo visibile l'icona di explorer
criteri = "*" & (Format(Me!Numero, "0000000") & ".*")
'criteri = Trim$(Format(Me!Numero, "0000000") & ".*")
'criteri = "Like '*' " & Format(Me!Numero, "0000000") & ".doc"
strEndFilePath = cartella & "\AD\DOC\" & Categoria
strLook = Dir(strEndFilePath & "\" & criteri)
If strLook = nomefilenumero Then
'If Dir(nomefpdf) = nomefilepdf Then
'If strLook <> "" Then
'ProcessFile = "File Present."
Me!cmd_file_con_nome.Visible = True
Else: Me!cmd_file_con_nome.Visible = False
End If
Hope what I said make sense.
I will appreciate your help.
I’m looking for some piece of code to list files in directory but with some filter.
I must verify if I have simile files in directory.
I tried to use the code from but it’s not working like I would like.
I tried get in “listbox” (lstFileList) files contain number from [Numero] field (Numero field is numeric e.g. 0022038).
The name of the file could be a number e.g.: 0022038.doc
or mist COR-1LD-1871-1226-0022038.doc
If they exist, I would like only them, to show in listbox.
If possible only file names without full directory path.
Do you know how build a string with “LIKE” option to do the same?
This is part of code I tried to use to check if files are in directory:
Private Sub Form_Current()
Dim nomefnr, nomefnome, nomefpdf, cartella, Categoria, nomefilenumero, nomefilenome, nomefilepdf As Variant
Dim criteri As String
Dim, MyPath As String
'Prova di verificare il file
cartella = Application.CurrentProject.Path
Categoria = Me!Categoria
MyPath = cartella & "\AD\DOC\" & Categoria & "\"
'''Verifico se ci sono i file nella directory
'Call ListFiles(MyPath, , "WHERE Me!Numero Like "*" & Format(Me!Numero, "0000000") & ".doc", Me.lstFileList)
'Call ListFiles(MyPath, , "*[! 0-9A-Z]*" & Format(Me!Numero, "0000000") & ".doc", Me.lstFileList)
End Sub
Call ListFiles is function from put in Modules.
---
I tried also so to make visible button to open a file (please don’t laugh) but this could be confuse if there are more file with same number. So I will go more in direction of listbox:
'''Verifico se il file con nome uguale al numero esiste
'''Se esiste, rendo visibile l'icona di explorer
criteri = "*" & (Format(Me!Numero, "0000000") & ".*")
'criteri = Trim$(Format(Me!Numero, "0000000") & ".*")
'criteri = "Like '*' " & Format(Me!Numero, "0000000") & ".doc"
strEndFilePath = cartella & "\AD\DOC\" & Categoria
strLook = Dir(strEndFilePath & "\" & criteri)
If strLook = nomefilenumero Then
'If Dir(nomefpdf) = nomefilepdf Then
'If strLook <> "" Then
'ProcessFile = "File Present."
Me!cmd_file_con_nome.Visible = True
Else: Me!cmd_file_con_nome.Visible = False
End If
Hope what I said make sense.
I will appreciate your help.