Finally! A use for AI: 15,000 images in a day


If you’ve been following 7 Generation Games for a while, you know two things; we are working on a platform to make educational games without code and I am skeptical of the AI hype. I keep reading that AI enables developers to work 30% ! 50%! 100%! faster. AI can replace junior developers! So far, I have found none of this to be true -until this weekend. (Yes, I work on weekends. Don’t judge.)

I often read that AI like Copilot is great for boilerplate tasks like creating a web page to collect emails for a newsletter. However, I seldom do any tasks like that and there are already plugins and plenty of example code online to do that, which is probably where Copilot, Gemini etc. are finding that code to write.

How Gemini Made My Day

Today, I did need to do a few of those standard tasks. Specifically, I had thousands of images we had created over several years of making games. As you can see from the examples below, these included everything from a tree indigenous to southern Chile to an explanation of how to find the area of a rectangle. These were all in subdirectories by the game in which they were used in a directory with a name like game_artwork.

Steps coded by Gemini

You might think that a directory with the name game_artwork would only include game artwork. You would be logical and wrong. There were many non-artwork files in there. Also, since the same dog or tree might be used in multiple games, the same file might be in six places. Here is what I wanted to do:

  1. Copy all of the files that were .png, .svg, .jpg and .gif into one directory
  2. Copy all of the PSD files into another directory
  3. Do nothing with all of the other files – .mov, documents, spreadsheets, etc.
  4. Remove duplicates from the two directories
  5. Count the number of files in each directory
  6. Export two txt files, one with only file names and one with file names, size and location.

I had been wanting to do something with Google apps scripts but never gotten around to it. Within in an hour I had working code from Gemini. It was not flawless the first time but it did save me hours. You can jump to the end to see code written by Gemini.

Why Gemini Worked So Well

There are two reasons I think Gemini worked well in this case. First of all, this is exactly the kind of standard task that many people want to do, as opposed to, for example, creating a platform to make educational games, which is where these images will be used. Secondly, I know a fair amount about both the files I was sorting and Javascript, which the Google apps scripts Gemini produced were written in.

Not perfect, but good

When the first pass returned a bunch of files like ._jaguar.png I knew that those were not art files and it took me just a minute to edit code to exclude those. For some reason, the section of the code produced by Gemini NOT to copy files if these files already existed in the directory did not work. I could have spent more time debugging it, but I just told Gemini to create a new script to delete duplicates out of a directory, which I ran after the first program and that did work. The first pass at deleting the duplicates by Gemini included the timestamp in the IF statement and ended up retaining too many duplicate files, so I edited that part.

The initial program written by Gemini copied the art files in each directory but not the subdirectory. For example, if the SpiritLakeGame directory had 50 art files and two subdirectories named Characters and Backgrounds , only the 50 art files were copied. I needed to modify the program so that it copied everything.

Now that I have all of the files I want in one directory and nothing else, the next step is to sort those into subdirectories.

In case you are wondering, the reason I needed these files categorized, it is so users of our game builder can easily find the images they need. Making an application to enable anyone who can type, point and click to make an educational game, is NOT the type of coding for which I have found AI to be useful, but I’m learning to apply AI wherever I can to reduce development time so we can deliver the game builder by year-end for the lowest cost possible. If you want to get our developer (low-code) version now or be on the mailing list for when the no-code platform is available, you get get on our mailing list by entering your email at the bottom of this page.

Code written by Gemini (and edited by me) to delete duplicates

function deleteDuplicateFiles() {
  // Get the ID of the folder to check for duplicates
  const folderId = 'my_file_ID'; 

  // Get the folder object
  const folder = DriveApp.getFolderById(folderId);

  // Get all files within the folder
  const files = folder.getFiles();

  // Create a map to store file information (key: filename + fileSize, value: file object)
  const fileMap = {};

  while (files.hasNext()) {
    const file = files.next();
    const fileName = file.getName();
    const fileSize = file.getSize();
  
 const fileKey = `${fileName}_${fileSize}`; 
    // Check if a file with the same key already exists
    if (fileMap[fileKey]) {
      // Delete the duplicate file
      file.setTrashed(true); 
      Logger.log(`Deleted duplicate file: ${fileName}`);
    } else {
      // Store the file information in the map
      fileMap[fileKey] = file; 
    }
  }
}

Leave a comment

Your email address will not be published. Required fields are marked *