Pregunta

I want to get all the files from a folder using DirectoryInfo, how can i perform check and get all the images from the folder, For checking i want to pass a productid as all the images are saved with their productids, for instance a product (bmw) has a product id 100 ,

Any ideas or tutorials of how to workout this. Your help will be appreciated .

¿Fue útil?

Solución

You can use a searchfilter when using Directory.GetFiles with wildcards in it

Dim files As String() = Directory.GetFiles("c:\", string.Format("{0}*.jpg", productId)

The * in the searchFilter is a wildcard. Anything that matches the first part which is the productId and ends with .jpg is going to match the filtering criteria

This function will return a list of strings of all the matching files. In the result you will have the full path to each file.

The filter above would match all of these if the productId is set to "101": 101_1.jpg 101_10.jpg 101_100.jpg

but would not match because the first part of the criteria is not fullfilled then. 100_1.jpg

Otros consejos

as you know you will be passing the productid, and filename is a string so you can always check filename.substring(0,3)== your productid if it is same then the correct images for that proudct id are saved

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top