How to count imgae files in a folder
-
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path. At present, my approach has been to specify the path via code such as @"C:\My Program\Folder"; Any help would be appreciated.
-
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path. At present, my approach has been to specify the path via code such as @"C:\My Program\Folder"; Any help would be appreciated.
-
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path. At present, my approach has been to specify the path via code such as @"C:\My Program\Folder"; Any help would be appreciated.
-
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path. At present, my approach has been to specify the path via code such as @"C:\My Program\Folder"; Any help would be appreciated.
You can use DirectoryInfo to get all files in a specific folder, you can also get it to only return files with specific file extensions, so look up how to use directoryinfo, and start making a list of all the file extensions that your image files have.
My current favourite word is: Waffle Cheese is still good though.
-
You can use DirectoryInfo to get all files in a specific folder, you can also get it to only return files with specific file extensions, so look up how to use directoryinfo, and start making a list of all the file extensions that your image files have.
My current favourite word is: Waffle Cheese is still good though.
-
if you know the file type, the easiest way is use Directory.GetFiles(path, "*.ext"); it will return a string array, you can get the file count using Properties of Length
-
Then you can use System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); to get all supported image format, or you could create your own image format array to loop the extension as I mention(and what you did).