Help creating shell script

tecseg

New member
Please, I'm novice in programming. Could someone help me to create a script for:

Leia a data de modificação dos arquivos em uma pasta.
Save the data in a variable.
Use the variable to create the folders I'm going to move the files into.
Move files to folders created according to modified date.

Thank you very much in advance.
 

Jacob L

Moderator (Lawsonator)

You can use the mv command. mv /storage/emulated/0/test.jpg /storage/emulated/0/MacroDroid/test.jpg moves the file into the MacroDroid folder.

You can rename files here too if you need.


mv /storage/emulated/0/test.jpg /storage/emulated/0/test1.jpg renames files
 

tecseg

New member
But before moving I need to read the modification date of the files and save them in a variable to create folders with that information and then move to these folders.
 

Jacob L

Moderator (Lawsonator)
You can create folders with mkdir.

mkdir /storage/emulated/0/Test creates a folder called test.

You can use the notification received trigger and variables to hold data
 

feraujo

New member
I can't read the modification date of the files and save it in a variable to use that variable to create the folders before moving the files
 

feraujo

New member
Now I'm watching your video and seeing that you explain this variable problem, I'm going to see if I get it, thank you very much. I have subscribed to your YouTube channel
 

feraujo

New member
it is giving an error message when listing the files in the folder and saving to the variable. i did as you explain in the video
 

Attachments

  • Screenshot_2023-03-18-15-35-40-434_com.arlosoft.macrodroid.jpg
    Screenshot_2023-03-18-15-35-40-434_com.arlosoft.macrodroid.jpg
    417.9 KB · Views: 7

tecseg

New member
Good morning friend, I couldn't, could you help me please. I looked it up on your youtube channel but it's all in English and I don't speak English. I have to translate to understand and sometimes the translation is not correct. I apologize for the mistakes. If you have support material please send me that I need to take a course to better understand the macrodroid.
 

feraujo

New member
Below is an example of a Bash script that creates folders with the modification date of the files and moves the files to these folders:

#!/bin/bash

# diretório dos arquivos a serem movidos
dir='/caminho/para/os/arquivos'

# loop pelos arquivos no diretório
for file in "$dir"/*
do
# verifica se é um arquivo
if [ -f "$file" ]; then
# obtém a data de modificação do arquivo
modified=$(date -r "$file" +%Y-%m-%d)

# cria a pasta com a data de modificação, caso não exista
if [ ! -d "$dir/$modified" ]; then
mkdir "$dir/$modified"
fi

# move o arquivo para a pasta com a data de modificação
mv "$file" "$dir/$modified/"
fi
done
 
Top