I am writing a script to help me keep my files organized. Essentially, I would like the script to organize my files based on their extension. The current solution looks at everything in a given directory. This is a problem because folders with dots in their name get moved.
I wanted to know if there is an if statement
that can be used to check if the directory is an actual directory or not. If it is indeed a directory, then the script should not move it.
Here is the code portion. I'm using a for loop
to iterate through the files, this is based roughly off an old batch script I had in windows, so this may not be the best way to go. Please let me know if there is a better solution:
#!/bin/bash
for i in *.*; do
filename=$(basename -- "$i")
extension="${filename##*.}"
extension="$extension"files
mkdir -p "$extension"
mv "$i" "$extension"
done
find
's output to a file, then looping over acat
of that file has the same problems outlined in Kusalanada's link. I don't see how this edit was an improvement. – Kevin Kruse Sep 11 '18 at 13:06