this post was submitted on 13 Jun 2023
6 points (100.0% liked)

Linux

48332 readers
420 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I wrote a script that manages the files of GoPro footage, thumbnails and the low resolution copy of the video files. It asks for the footage directory and has the option to rename all files equally so they can be selected, separated, or processed easier, or move all the low resolution copies into another folder in the same directory.

Besides posting it on GitHub is there anywhere else I can upload it or share it?

you are viewing a single comment's thread
view the rest of the comments
[–] IOu1 1 points 1 year ago

I guess I'll post it here then:

#!/bin/bash

# Function to display the menu
display_menu() {
  echo "Select an option:"
  echo "1. Move all .LRV files to 'LRV' directory"
  echo "2. Undo move operation"
  echo "3. Rename files starting with 'GL' to 'GX'"
  echo "4. Undo renaming operation for .LRV files"
  echo "5. Exit"
  read -p "Enter choice (1, 2, 3, 4, or 5): " choice
}

# Function to handle option 1
move_lrv_files() {
  # Create the LRV directory
  mkdir "LRV"

  # Move all the .LRV files to the LRV directory
  mv *.LRV "LRV"
  echo "Moved all .LRV files to 'LRV' directory"
}

# Function to handle option 2
undo_move_operation() {
  # Move all .LRV files back to the working directory
  mv LRV/*.LRV .

  # Remove the LRV directory
  rmdir LRV
  echo "Undid move operation"
}

# Function to handle option 3
rename_files() {
  # Rename files starting with 'GL' to 'GX'
  for file in GL*; do
    newname="${file/GL/GX}"
    mv "$file" "$newname"
    echo "Renamed file '$file' to '$newname'"
  done
}

# Function to handle option 4
undo_rename_files() {
  # Undo renaming operation for .LRV files (revert files from 'GX' to 'GL')
  for file in GX*.LRV; do
    newname="${file/GX/GL}"
    mv "$file" "$newname"
    echo "Renamed file '$file' to '$newname'"
  done
}

# Main script
if [[ $1 == "-d" ]]; then
  # Use directory provided as command-line argument
  directory=$2
else
  # Ask user for the working directory
  read -p "Please enter the path of the working directory: " directory
fi

# Change the working directory and check if it was successful
if cd "$directory"; then
  while true; do
    display_menu

    # Check user choice and execute the appropriate function
    case $choice in
      1)
        move_lrv_files
        ;;
      2)
        undo_move_operation
        ;;
      3)
        rename_files
        ;;
      4)
        undo_rename_files
        ;;
      5)
        echo "Exiting..."
        break
        ;;
      *)
        echo "Invalid choice"
        ;;
    esac

    echo
  done
else
  # Error message if cd command fails
  echo "Error: Invalid path. Please double check the working directory."
fi