0

I need to count and check how much of some images is placed in folder od web server. Example- images get names from user_id, and on example I have user_id 27, and my images are:

27_1.jpg, 27_2.jpg, 27_3.jpg, ...

How to check and write to database this thing?

Thanks

Kristijan Iliev
  • 4,827
  • 9
  • 28
  • 46
Wizard4U
  • 3,917
  • 4
  • 18
  • 14

2 Answers2

4

Once you know your path you can use IO.Directory.GetFiles() method.

IO.Directory.GetFiles("\translated\path","27_*.jpg").Count()

will give you what you're looking for.

hometoast
  • 11,293
  • 4
  • 39
  • 57
0

Using the System.IO namespace, you can do something like this

public File[] GetUserFiles(int userId)
{
   List<File> files = new List<File>();

   DirectoryInfo di = new DirectoryInfo(@"c:\folderyoulookingfor");
   foreach(File f in di.GetFiles())
   {
      if(f.ToString().StartsWith(userId.ToString()))
         files.Add(f);
   }
   return file.ToArray();
}
WebDude
  • 6,035
  • 5
  • 32
  • 44