Última actividad 1725615111

Malin's Avatar Malin revisó este gist 1725615110. Ir a la revisión

1 file changed, 32 insertions

unzip-rename-dir.sh(archivo creado)

@@ -0,0 +1,32 @@
1 + #!/bin/bash
2 +
3 + # Loop through all ZIP files in the current directory
4 + for zipfile in *.zip; do
5 + # Check if the file exists (in case no .zip files are found)
6 + [ -e "$zipfile" ] || continue
7 +
8 + # Get the filename without the .zip extension
9 + dirname="${zipfile%.zip}"
10 +
11 + # Create a temporary directory for extraction
12 + temp_dir=$(mktemp -d)
13 +
14 + # Extract the ZIP file to the temporary directory
15 + unzip -q "$zipfile" -d "$temp_dir"
16 +
17 + # If the extraction was successful, rename the directory
18 + if [ $? -eq 0 ]; then
19 + # Remove existing directory if it exists
20 + [ -d "$dirname" ] && rm -rf "$dirname"
21 +
22 + # Rename the temporary directory to the ZIP filename (without .zip)
23 + mv "$temp_dir" "$dirname"
24 + echo "Extracted and renamed: $zipfile -> $dirname"
25 + else
26 + echo "Failed to extract: $zipfile"
27 + # Clean up the temporary directory in case of failure
28 + rm -rf "$temp_dir"
29 + fi
30 + done
31 +
32 + echo "Extraction and renaming complete!"
Siguiente Anterior