Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Gelöst] unfoo + automatische Unterordnererstellung
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
Ätherischer Wanderer
n00b
n00b


Joined: 28 Dec 2004
Posts: 59

PostPosted: Sat Sep 24, 2005 2:51 pm    Post subject: [Gelöst] unfoo + automatische Unterordnererstellung Reply with quote

Hallo! :D
Weis jemand einen Befehl, mit dem man per unfoo mehrere Dateien, die im selben Ordner liegen, in vom Archivnamen (mit Leerzeichen) abgeleitete Unterordner (ohne Dateierweiterung) entpacken kann?

Beispiel:

In meinem Ordner liegen folgende Dateien:

Code:

gut.zip
besser.rar
am besten.tar


Der Inhalt jeder Datei landet in einem extra Ordner

Code:

../
gut/
besser/
am besten/


Hab (noch) keine Ahnung von Bash-Skripten, aber vielleicht gehts ja auch ganz einfach durch Pipes?


Last edited by Ätherischer Wanderer on Sat Sep 24, 2005 5:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
SinoTech
Advocate
Advocate


Joined: 20 Mar 2004
Posts: 2579
Location: Neunkirchen / Saarland / Germany

PostPosted: Sat Sep 24, 2005 4:50 pm    Post subject: Reply with quote

Naja, also mit pipes alleine dürftest du da nicht allzuweit kommen.
Ein Bash-Script würde in etwa so aussehen:
(extract.sh)
Code:

#!/bin/bash

if [[ $# == 0 ]]
then
   echo "Usage: $0 archiv1 archiv2 ..." >&2
fi


while [[ -n "$1" ]]
do
   # FILE_TYPE gibt den Dateityp an
   # (Also o es sich um ein "tar"-Archiv, ein "zip"-Archiv, ... handelt)
   FILE_TYPE=${1##*.}
   # Dateiname ohne Dateiendung
   # (Brauchen wir um das Verzeichniss anzulegen)
   DEST_DIR=${1%%.*}
   
   mkdir "${DEST_DIR}"

   case ${FILE_TYPE} in
   zip)
      unzip "$1" -d "${DEST_DIR}"
      ;;
   rar)
      unrar x "$1" "${DEST_DIR}"
      ;;
   tar)
      tar -xf "$1" -C "${DEST_DIR}"
      ;;
   tgz)
      tar -xzf "$1" -C "${DEST_DIR}"
      ;;
   esac

   shift
done

Aufruf
Code:

$ extract.sh gut.zip besser.rar "am besten.tar"


!!! Habe es allerdings noch nicht getestet !!!

Mfg

Sino
Back to top
View user's profile Send private message
Ätherischer Wanderer
n00b
n00b


Joined: 28 Dec 2004
Posts: 59

PostPosted: Sat Sep 24, 2005 5:20 pm    Post subject: Reply with quote

SinoTech wrote:

!!! Habe es allerdings noch nicht getestet !!!


Ich aber :o. Funktioniert perfekt, vielen dank :).

Werde mich auch mal ans Skripten rantasten, dein Skript sieht ja recht logisch aus.
Back to top
View user's profile Send private message
SinoTech
Advocate
Advocate


Joined: 20 Mar 2004
Posts: 2579
Location: Neunkirchen / Saarland / Germany

PostPosted: Sat Sep 24, 2005 5:42 pm    Post subject: Reply with quote

Ätherischer Wanderer wrote:

[...]
Ich aber :o. Funktioniert perfekt, vielen dank :).
[...]

No prob :)

Ätherischer Wanderer wrote:

[...]
Werde mich auch mal ans Skripten rantasten, dein Skript sieht ja recht logisch aus.

Tjo, bash-scripts sind ziemlich nützlich, keine Ahnung wie ich unter Windows blos ohne ausgekommen bin :D.
Kannst ja posten oder eine PM schreiben falls du Fragen hast.

Mfg

Sino
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum