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,901
  • 10
  • 28
  • 47
Wizard4U
  • 3,997
  • 4
  • 19
  • 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,522
  • 5
  • 41
  • 58
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,125
  • 5
  • 33
  • 44