Skip to content

Instantly share code, notes, and snippets.

@CuddlyBunion341
Created June 5, 2025 08:27
Show Gist options
  • Save CuddlyBunion341/10584b6616c0c48c198d7bc508307c93 to your computer and use it in GitHub Desktop.
Save CuddlyBunion341/10584b6616c0c48c198d7bc508307c93 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if a directory to flatten is provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <directory_to_flatten> <target_directory>"
exit 1
fi
SOURCE_DIR="$1"
TARGET_DIR="$2"
# Check if the source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Directory '$SOURCE_DIR' does not exist."
exit 1
fi
# Create the target directory if it does not exist
mkdir -p "$TARGET_DIR"
# Find all files in the source directory and subdirectories
find "$SOURCE_DIR" -type f | while read -r file; do
# Get the filename without the path
filename=$(basename "$file")
# Move the file to the target directory
# If a file with the same name exists, append a number to the filename
target_file="$TARGET_DIR/$filename"
if [ -e "$target_file" ]; then
counter=1
while [ -e "$target_file" ]; do
target_file="$TARGET_DIR/${filename%.*}_$counter.${filename##*.}"
counter=$((counter + 1))
done
fi
mv "$file" "$target_file"
echo "Moved: $file -> $target_file"
done
echo "Flattening complete."
@CuddlyBunion341
Copy link
Author

Before

./0 – Einfuhrung und Tooling
./0 – Einfuhrung und Tooling/00 PROG2 Einfuhrung.pdf
./0 – Einfuhrung und Tooling/00 Tooling Build-Automation.pdf
./1 - Concurrency-Execution
./1 - Concurrency-Execution/01 Concurrency 1 – Foundation - Code.zip
./1 - Concurrency-Execution/01 Concurrency 1 – Foundation.pdf
./1 - Concurrency-Execution/02 Concurrency 2 - Executor Framework.pdf
./1 - Concurrency-Execution/02 Concurrency 2 – Executor Framework - Code.zip
./1 - Concurrency-Execution/Lab01-Concurrency-Execution-Solution.zip
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/Einreichungen
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)/Feedback
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)/Feedback/Feedback als Kommentar.html
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/intro
./1 - Concurrency-Execution/Praktikum 01 – Concurrency - Execution/intro/intro.html
./2 - Graphical User-Interfaces
./2 - Graphical User-Interfaces/03 GUI 1 – Foundation - Code.zip
./2 - Graphical User-Interfaces/03 GUI 1 – Foundation.pdf
./2 - Graphical User-Interfaces/04 GUI 2 – Toolbox - Code.zip
./2 - Graphical User-Interfaces/04 GUI 2 – Toolbox.pdf
./2 - Graphical User-Interfaces/04 GUI – JavaFXML Workshop.html
./2 - Graphical User-Interfaces/04 GUI – JavaFXML Workshop.pdf
./2 - Graphical User-Interfaces/Lab02-GUI-Solution.zip
./2 - Graphical User-Interfaces/Praktikum 02 – GUI
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/Einreichungen
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)/Feedback
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/Einreichungen/Daniel Bengl (T LE-T-BA-IT-24HS-TAWIN)/Feedback/Feedback als Kommentar.html
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/intro
./2 - Graphical User-Interfaces/Praktikum 02 – GUI/intro/intro.html
./3 - Concurrency-Cooperation
./3 - Concurrency-Cooperation/05 Concurrency 3 – Thread Cooperation - Code.zip
./3 - Concurrency-Cooperation/05 Concurrency 3 – Thread Cooperation.pdf
./3 - Concurrency-Cooperation/06 Concurrency 4 – Deadlocks - Code.zip
./3 - Concurrency-Cooperation/06 Concurrency 4 – Deadlocks.pdf
./3 - Concurrency-Cooperation/Lab03-Concurrency-Cooperation-Solution.zip
./3 - Concurrency-Cooperation/Praktikum 03 – Concurrency - Cooperation
./3 - Concurrency-Cooperation/Praktikum 03 – Concurrency - Cooperation/intro
./3 - Concurrency-Cooperation/Praktikum 03 – Concurrency - Cooperation/intro/intro.html
./4 - Mock-Testing
./4 - Mock-Testing/07 MockTesting - Code.zip
./4 - Mock-Testing/07 TestingPrinciplesAndMockTesting.pdf
./4 - Mock-Testing/Lab04-Mock-Testing-Solution.zip
./4 - Mock-Testing/Praktikum 04 – Mock-Testing
./4 - Mock-Testing/Praktikum 04 – Mock-Testing/intro
./4 - Mock-Testing/Praktikum 04 – Mock-Testing/intro/intro.html
./5 - Input - Output
./5 - Input - Output/08 IO 1 - FilesIOStreams - Code.zip
./5 - Input - Output/08 IO 1 – Files-Streams.pdf
./5 - Input - Output/09 IO 2 - Advanced - Code.zip
./5 - Input - Output/09 IO 2 - Advanced.pdf
./5 - Input - Output/Lab05-InputOutput-Solution.zip
./5 - Input - Output/Praktikum 05 – Java Input  Output
./5 - Input - Output/Praktikum 05 – Java Input  Output/intro
./5 - Input - Output/Praktikum 05 – Java Input  Output/intro/intro.html
./6 - Functional Programming
./6 - Functional Programming/10 Functional Programming 1 - F___terfaces and Lambda Expression.pdf
./6 - Functional Programming/10 Functional Programming 1 - LambdaExpressions - Code.zip
./6 - Functional Programming/11 Functional Programming 2 - FunctionalStreams - Code.zip
./6 - Functional Programming/11 Functional Programming 2 - Streams.pdf
./6 - Functional Programming/Lab06-FunctionalProgramming-Solution.zip
./6 - Functional Programming/Praktikum 06 – FunctionalProgramming
./6 - Functional Programming/Praktikum 06 – FunctionalProgramming/intro
./6 - Functional Programming/Praktikum 06 – FunctionalProgramming/intro/intro.html
./Kursinformation (Leistungsnachweise, Semesterplan, Unterlagen)
./Kursinformation (Leistungsnachweise, Semesterplan, Unterlagen)/Kursorganisation.html
./Kursinformation (Leistungsnachweise, Semesterplan, Unterlagen)/Leistungsnachweise.html
./Kursinformation (Leistungsnachweise, Semesterplan, Unterlagen)/Wochenplan WIN – Donnerstag.html
./Semesterendprufung
./Semesterendprufung/Prufungsinformationen und -bedingungen.html

After

./.DS_Store
./00 Tooling Build-Automation.pdf
./01 Concurrency 1 – Foundation - Code.zip
./01 Concurrency 1 – Foundation.pdf
./02 Concurrency 2 - Executor Framework.pdf
./02 Concurrency 2 – Executor Framework - Code.zip
./03 GUI 1 – Foundation - Code.zip
./03 GUI 1 – Foundation.pdf
./04 GUI 2 – Toolbox - Code.zip
./04 GUI 2 – Toolbox.pdf
./04 GUI – JavaFXML Workshop.html
./04 GUI – JavaFXML Workshop.pdf
./05 Concurrency 3 – Thread Cooperation - Code.zip
./05 Concurrency 3 – Thread Cooperation.pdf
./06 Concurrency 4 – Deadlocks - Code.zip
./06 Concurrency 4 – Deadlocks.pdf
./07 MockTesting - Code.zip
./07 TestingPrinciplesAndMockTesting.pdf
./08 IO 1 - FilesIOStreams - Code.zip
./08 IO 1 – Files-Streams.pdf
./09 IO 2 - Advanced - Code.zip
./09 IO 2 - Advanced.pdf
./10 Functional Programming 1 - F___terfaces and Lambda Expression.pdf
./10 Functional Programming 1 - LambdaExpressions - Code.zip
./11 Functional Programming 2 - FunctionalStreams - Code.zip
./11 Functional Programming 2 - Streams.pdf
./Feedback als Kommentar.html
./Feedback als Kommentar_1.html
./Kursorganisation.html
./Lab01-Concurrency-Execution-Solution.zip
./Lab02-GUI-Solution.zip
./Lab03-Concurrency-Cooperation-Solution.zip
./Lab04-Mock-Testing-Solution.zip
./Lab05-InputOutput-Solution.zip
./Lab06-FunctionalProgramming-Solution.zip
./Leistungsnachweise.html
./Prufungsinformationen und -bedingungen.html
./Wochenplan WIN – Donnerstag.html
./intro.html
./intro_1.html
./intro_2.html
./intro_3.html
./intro_4.html
./intro_5.html

1 directory, 44 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment