https://github.com/carterlasalle/script-and-tools
This repository is a collection of various scripts written in Python, Shell (.sh), and other languages. The scripts perform a variety of tasks and you can use them as per your requirements.
https://github.com/carterlasalle/script-and-tools
python python3 random script scripts tools
Last synced: 2 months ago
JSON representation
This repository is a collection of various scripts written in Python, Shell (.sh), and other languages. The scripts perform a variety of tasks and you can use them as per your requirements.
- Host: GitHub
- URL: https://github.com/carterlasalle/script-and-tools
- Owner: carterlasalle
- License: mit
- Created: 2023-05-11T21:04:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-11T21:27:52.000Z (about 2 years ago)
- Last Synced: 2024-07-12T23:34:03.570Z (11 months ago)
- Topics: python, python3, random, script, scripts, tools
- Language: Shell
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# script-and-tools
This repository is a collection of various scripts written in Python, Shell (.sh), and other languages. The scripts perform a variety of tasks and you can use them as per your requirements.
Please note that these scripts don't accept arguments such as `-d`. You need to manually input the directory in the scripts. The suffixes in the scripts can be changed according to your needs.
## Current Scripts
Currently, the repository contains the following scripts:
1. **removesuffixoffile.sh:** This script removes specified suffixes from the file names in the provided directories. The script currently removes suffixes such as `_door`, `_stairs`, and `_above`.
2. **separatefilesintofoldersbysuffix.sh:** This script separates files into different folders based on their suffixes. It creates directories named `above`, `stairs`, and `door` and moves files with corresponding suffixes into these directories.
### removesuffixoffile.sh
```bash
#!/bin/bash# The directories to be processed. Put your directories here:
directories=("")# Process each directory
for directory in "${directories[@]}"; do
# Process each file in the directory
for file in "$directory"/*; do
echo "Processing file: $file"
# Get the base filename without the extension
base_name=$(basename "$file" .png)
# Remove the suffix from the base filename
new_base_name=$(echo "$base_name" | sed -e 's/_door//' -e 's/_stairs//' -e 's/_above//')
# Construct the new filename with the directory and extension
new_name="$directory/$new_base_name.png"
# Only rename the file if the new name is different
if [[ "$file" != "$new_name" ]]; then
echo "Renaming $file to $new_name"
mv "$file" "$new_name"
fi
done
done
```
### separatefilesintofoldersbysuffix.sh```bash
#!/bin/bash# The directory to be processed. Put your directory here:
directory=""# Directories where files will be moved
above_dir="${directory}/above"
stairs_dir="${directory}/stairs"
door_dir="${directory}/door"# Create the directories if they don't exist
mkdir -p "$above_dir"
mkdir -p "$stairs_dir"
mkdir -p "$door_dir"# Process each file in the directory
for file in "$directory"/*; do
echo "Processing file: $file"
if [[ $file == *_above* ]]; then
echo "Moving $file to $above_dir"
mv "$file" "$above_dir"
elif [[ $file == *_stairs* ]]; then
echo "Moving $file to $stairs_dir"
mv "$file" "$stairs_dir"
elif [[ $file == *_door* ]]; then
echo "Moving $file to $door_dir"
mv "$file" "$door_dir"
fi
done
```## Usage
To use the scripts, you need to update the directories in the scripts to match your requirements.
### removesuffixoffile.sh
In the `removesuffixoffile.sh` script, update the `directories` variable with the directories you want to process. For example:
```bash
directories=("/path/to/directory1" "/path/to/directory2")
separatefilesintofoldersbysuffix.sh
```In the separatefilesintofoldersbysuffix.sh script, update the directory variable with the directory you want to process. For example:
```bash
directory="/path/to/directory"
```### Running the Scripts
After you have updated the scripts with your directories, you can run them from a terminal as follows:
```bash
bash removesuffixoffile.sh
```
```bashbash separatefilesintofoldersbysuffix.sh
```
### Changing SuffixesThe scripts are currently set up to work with file suffixes _above, _stairs, and _door. If you want to use different suffixes, you can change them in the scripts.
In the removesuffixoffile.sh script, you can change the suffixes in the sed command:
```bash
new_base_name=$(echo "$base_name" | sed -e 's/_your_suffix//' -e 's/_your_suffix//' -e 's/_your_suffix//')
```
In the separatefilesintofoldersbysuffix.sh script, you can change the suffixes in the if statements:```bash
if [[ $file == *_your_suffix* ]]; then
echo "Moving $file to $your_dir"
mv "$file" "$your_dir"
```
## ContributingContributions to this repository are welcome. Feel free to submit a pull request with your script.