<jupyter_start><jupyter_text>OverviewA *C* utility to split images in the format `namepart1_namepart2_index.jpg` (or for that matter `name_index.jpg` into corresponding image folders of `name/index.jpg`. This utility require a C kernel to run.This program is used to process the **images** folder from [Cats and Dogs Breeds dataset](https://www.kaggle.com/zippyz/cats-and-dogs-breeds-classification-oxford-dataset). It must be run on **the folder that contains the *images* folder** (i.e. inside the parent folder of **images** folder).<jupyter_code>// Namepsaces
using System.IO;
using System.Linq;
using System.Globalization;
// (Sanity check) See whether we have file names not ends with .jpg
foreach(string s in Directory.GetFiles("images").Where(f => f.EndsWith(".jpg") == false))
{
    Console.WriteLine($"Deleting file: {s}");
    File.Delete(s);
}
// (Sanity check) Get all unique breeds
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
var breeds = Directory.GetFiles("images").Select(f => 
                                    {
                                        // Get file name
                                        string name = Path.GetFileNameWithoutExtension(f);
                                        // Get breed name
                                        string breed = ti.ToTitleCase(name.Substring(0, name.LastIndexOf('_')).Replace('_', ' '));
                                        return breed;
                                    }).Distinct().ToList();
Console.WriteLine("Available breeds: ");
breeds.ForEach(b => Console.WriteLine($"- {b}"));
// Create directories for breeds
breeds.ForEach(b => Directory.CreateDirectory(b));
// Put files into corresponding subfolders
string[] files = Directory.GetFiles("images");
Console.WriteLine($"Process {files.Length} files.");
foreach(string f in files)
{
    // Get file name
    string name = Path.GetFileNameWithoutExtension(f);
    string extension = Path.GetExtension(f);
    // Get breed name
    int split = name.LastIndexOf('_');
    string breed = ti.ToTitleCase(name.Substring(0, split).Replace('_', ' '));
    // Move the file into corresponding folder
    string newName = $"{name.Substring(split + 1)}{extension}";
    string folder = Path.GetDirectoryName(f);
    string newPath = Path.Combine(Directory.GetCurrentDirectory(), breed, newName);
    File.Move(f, newPath);
}
// Delete the images folder
Directory.Delete("images");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1267318663406683, 'fraction_numerical': 0.002037489812550937, 'mean_word_length': 2.8359375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '349362', 'license': 'MIT', 'n_tokens_mistral': 669, 'n_tokens_neox': 650, 'n_words': 190, 'path': 'tools/Cats_and_Dogs_Breeds_Dataset_Utility.ipynb', 'repo_name': 'NirooshKa/APS360-Cold-Start-Problem', 'size': '2454'}