![Script to copy TensorArt downloaded .png into parsed modelname subfolders TAMS 2.0 (linux)](https://image.tensorartassets.com/cdn-cgi/image/anim=false,plain=false,w=320,q=85/article/661323374995269704/1325a549-69fe-4ff5-a241-24eee7638864.png)
Script to copy TensorArt downloaded .png into parsed modelname subfolders TAMS 2.0 (linux)
IntroductionI wrote this gnu/linux bash script to parse downloaded files from TAMS 2.0, get the model name from the exif, and copy the file into a model name sub-folder. Why? Why not.PreReqexiftool from: https://exiftool.org/ I extracted it to my home folder.jq from: sudo apt-get install jqperl from: it was already installed for melinux? (I don't know how to do this in macOS/Windows, sorry)ScriptPaste this code into: something.shRead each line because it's unsafe to run random scriptsChange the two directory paths at the topChange the path to exiftool if needed (the ~/ExifTool/exiftool)Make it executable: chmod +x something.shThen just run it like: ./something.sh.. if it looks okay delete the downloaded files. Can change copy to move if feeling brave#!/bin/bash
# Directory containing the .png files
src_dir="/home/contoso/Downloads"
# Directory to copy files to
dest_base_dir="/home/contoso/Downloads/test"
# Loop through all .png files in the source directory
for file in "$src_dir"/*.png; do
# Extract the modelFileName from the EXIF data
modelFileName=$(perl ~/ExifTool/exiftool -if '($Prompt =~/ckpt_name/i)' -Generation_data "$file" -s3 -q | jq -r '.baseModel.modelFileName')
# Sanitize the model name to prevent code injection
sanitized_modelname=$(echo "$modelFileName" | sed 's/[^a-zA-Z0-9_-]//g')
echo "$sanitized_modelname"
# Check if sanitized_modelname is not empty
if [ -n "$sanitized_modelname" ]; then
# Create the destination directory if it doesn't exist
dest_dir="$dest_base_dir/$sanitized_modelname"
mkdir -p "$dest_dir"
# Copy the file to the destination directory
cp "$file" "$dest_dir/"
fi
done
NotesExifTool created by Phil Harvey. Very impressive. Active community and forum at the creator's website.Maybe this is an "exiftool common scripting error #3" but I can't find an easy way to get the model name from the JSON using only exiftool. If the exif had one separate line for model name then exiftool could read it as a simple tag and copy the files based on that.I only use this website to make AI pics. Maybe something else does this automatically but I am not installing local AI gen software and this works for me. Maybe it will inspire someone and solve a problem.Please understand this post isn't an offer for support. This took me a week to figure out. I don't know what I am doing.I am not responsible if this disappears your files or someone somehow injects code to rm -rf your data by naming a model with code injection. I asked bing to write code to sanitize the input variable.Okay bye.
![user_661323374995269704](https://image.tensorartassets.com/cdn-cgi/image/anim=false,plain=false,w=16,q=85/users/common/default_avatar.jpg)