View Single Post
  #1   (View Single Post)  
Old 13th August 2008
graudeejs's Avatar
graudeejs graudeejs is offline
Real Name: Aldis Berjoza
ISO Quartermaster
 
Join Date: Jul 2008
Location: Riga, Latvia
Posts: 589
Default my 1st sh script

This is still unfinished


Code:
#!/bin/sh

RenameFile()
{
  rm -f $1/*jpg
  rm -f $1/Thumbs.db
  rm -f $1/*.ini

  for fileName in $1/*
  do
    newFileName=$(echo "$fileName" | tr ' ' _)

    if [ "$fileName" != "$newFileName" ]
      then
        mv -f "$fileName" "$newFileName"
    fi

    if [ "`file -b "$newFileName"`" = "directory" ]
      then
        RenameFile "$newFileName"
      else
        chmod uog-x "$newFileName"
    fi

  done
}


RenameFile `pwd`
Code:
$ cd /home/share/music

$ mkplaylist.sh
chmod: /home/share/music/mp3/151/Code_Of_Tha_Street_[2003]/*: No such file or directory
chmod: /home/share/music/mp3/213/The_Hard_Way_[2004]/*: No such file or directory
chmod: /home/share/music/mp3/2Pac/2Pacalypse_Now_[1991]/*: No such file or directory
chmod: /home/share/music/mp3/2Pac/All_Eyez_On_Me_[1996]/*: No such file or directory
...
The top level files aren't renamed, and x flag ain't removed from permissions.
And i don't seem to get it why.

This script is supposed to rename all subdirectories and files in given directory so that they don't have spaces, remove windows crap files, and x attribute (which i have because i copied files from NTFS/FAT whatever)

Later i will make it also build playlists for my mplayer (which i run in slave mode), but that's another story....


plz, help me, i'm just starting to learn sh, and this is my 1st script that has more than 4 lines
Reply With Quote