extract only a .csv name file from url string

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

extract only a .csv name file from url string

Post by sal21 »

See in txt attached

for example:

ANPR_archivio_comuni.csv
comuni.csv
cap.csv
comuni_codici-catastali.csv
stemmi.csv

tks
You do not have the required permissions to view the files attached to this post.

snb
4StarLounger
Posts: 584
Joined: 14 Nov 2012, 16:06

Re: extract only a .csv name file from url string

Post by snb »

Adapt the path:

Code: Select all

Sub M_snb()
   msgbox join(filter(split(replace(createobject("scripting.filesystemobject").opentextfile("G:\OF\nomefilecsv.txt).readall,vbcrlf,"/"),"/"),".csv"),vblf)
End Sub

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: extract only a .csv name file from url string

Post by HansV »

If you prefer a loop:

Code: Select all

Sub Test()
    Dim f As Integer
    Dim all As String
    Dim lines() As String
    Dim i As Long
    Dim parts() As String
    Dim url As String
    f = FreeFile
    Open "C:\Test\nomefilecsv.txt" For Input As #f
    all = Input(LOF(f), f)
    Close #f
    lines = Split(all, vbCrLf)
    For i = 0 To UBound(lines)
        parts = Split(lines(i), "/")
        url = parts(UBound(parts))
        Debug.Print url
    Next i
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: extract only a .csv name file from url string

Post by sal21 »

HansV wrote:
01 Sep 2023, 10:51
If you prefer a loop:

Code: Select all

Sub Test()
    Dim f As Integer
    Dim all As String
    Dim lines() As String
    Dim i As Long
    Dim parts() As String
    Dim url As String
    f = FreeFile
    Open "C:\Test\nomefilecsv.txt" For Input As #f
    all = Input(LOF(f), f)
    Close #f
    lines = Split(all, vbCrLf)
    For i = 0 To UBound(lines)
        parts = Split(lines(i), "/")
        url = parts(UBound(parts))
        Debug.Print url
    Next i
End Sub
as usual you read my mind!

work perfect!
Tks bro