vb.net get filename list from wildcard

前端 未结 4 914
野趣味
野趣味 2021-01-27 13:48

I have string say \"c:\\debug\\ *.txt\" In Debug folder there are severeal .txt files , say test1.txt test2.txt test3.txt .

How can I get from this string c:\\debug\\ *.

4条回答
  •  心在旅途
    2021-01-27 14:39

    Use the GetFiles from My.Computer.System and the ReadOnlyCollection(of String) from the system.collections.objectModel import and a searchoption as desired (top or all)

    sPath = "C:\debug"     ' your desired path
    sFile1 = "t*.txt"      ' your desired search pattern with * wildcard
    sFile2 = "test?.txt"   ' your desired search pattern with ? wildcard  
    
    dim lstFiles as system.collections.ObjectModel.ReadOnlyCollection(of String) = My.Computer.Filesystem.GetFiles(sPath, FileIO.SearchOption.SearchTopLevelOnly, sFile1)
    
    'lstfiles contains all the files that match your selection 
    'if you really need an array you can convert the list to array here
    
    dim i as integer = 0
    for each sFile as string in lstfiles
        a(i)=sfile
        i+=1
    next
    

提交回复
热议问题