JosiahMaybe
Gold Coder
Ruby was much faster though so I think command should be faster not slower. Ruby was like instant. This is like take an hour.Here is like my current code.
Also, an oddity of that, it is not actually deleting when I just press enter. Should it be y?
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E.
function startXE() {
if [ -f "$1propsXE.txt" ]; then
echo "$1propsXE.txt exists";
rm -i "$1propsXE.txt";
echo "File deleted";
else
echo "$1propsXE.txt does not exist";
fi
recurseXE $1 "$1propsXE.txt";
echo "X E." >> "$1propsXE.txt";
#X E.
}
#X E.
function recurseXE() {
#save list of file name to variable
manifest="$(ls -a $1 | grep -v /)";
#echo "$(stat $1)";
writeXE $1 $2;
#iterate through each file name and pass it to stat to get birth, access, modify info
while IFS= read -r line; do
if [[ "$line" != ".." && "$line" != "." ]]; then
if [ -d "$1$line" ]; then
if [[ "$1$line" == */ ]]; then
recurseXE "$1$line" $2;
else
recurseXE "$1$line/" $2;
fi
#echo "$line";
else
writeXE $1 $2;
fi
#echo "$1$line"
fi
done <<< $manifest
#X E.
}
#X E.
function writeXE() {
echo $1 >> $2;
# Get the file's creation time using stat
created_at=$(stat -c %W $1);
# Get the timestamps using stat
modified_at=$(stat -c %y $1);
accessed_at=$(stat -c %x $1);
changed_at=$(stat -c %z $1);
# Format the creation time using the date command
formatted_created_at=$(date -d @$created_at +"%Y-%m-%d %H:%M:%S.%N");
# Format the timestamps using date
formatted_modified_at=$(date -d "$modified_at" +"%Y-%m-%d %H:%M:%S.%N");
formatted_accessed_at=$(date -d "$accessed_at" +"%Y-%m-%d %H:%M:%S.%N");
formatted_changed_at=$(date -d "$changed_at" +"%Y-%m-%d %H:%M:%S.%N");
echo $formatted_created_at >> $2;
echo $formatted_modified_at >> $2;
echo $formatted_accessed_at >> $2;
echo $formatted_changed_at >> $2;
echo "" >> $2;
# Store the output of the stat command in a variable
#output="$(stat $1)";
#output=($output);
# Use command substitution to split the output into an array
#readarray -t stat_array <<< "$output";
# Print the array elements
#for element in "${stat_array[@]}"; do
# if [[ $element == *"Access:"* ]]; then
# echo "access";
# fi
# if [[ $element == *"Modify:"* ]]; then
# echo "modify";
# fi
# if [[ $element == *"Change:"* ]]; then
# echo "change";
#fi
# if [[ $element == *"Birth:"* ]]; then
# echo "born";
# fi
#done
#X E.
}
#X E.
if [ $# -gt 0 ]; then
if [ -d "$1" ]; then
if [[ "$1" == */ ]]; then
startXE "$1";
else
startXE "$1/";
fi
fi
else
if [[ "$(pwd)" == */ ]]; then
startXE "$(pwd)";
else
startXE "$(pwd)/";
fi
fi
#X E.