![]() |
|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
![]() |
|
Thread Tools | Display Modes |
|
|||
![]() Code:
chmod: /home/share/music/mp3/151/Code_Of_Tha_Street_[2003]/*: No such file or directory You will have to escape the "[" with a "\" to make it a literal '[' and not the start of a shell "[ ..... ]" regular expression.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
![]()
I would do it like this ...
Code:
#!/bin/sh RenameFile() { cd ${1} for f in *; do nf=$(echo "${f}" | tr ' ' _) if [ "${f}" != "${nf}" ]; then mv -f "${f}" "${nf}" fi if [ -d "${nf}" ]; then RenameFile "${nf}" fi done cd - } find . -name "*.jpg" -or -name Thumbs.db -or -name "*.ini" -delete find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; RenameFile .
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
||||
![]() Quote:
try this: Code:
#!/bin/sh RenameFile() { find "$1" -depth | while read fileName ; do newFileName=$(echo "$fileName" | tr ' ' _) if [ "$fileName" != "$newFileName" ]; then mv -f "$fileName" "$newFileName" fi if [ -d "$newFileName" ] ; then rm -f "$newFileName"/*jpg "$newFileName"/Thumbs.db "$newFileName"/*.ini else chmod a-x "$newFileName" fi done } RenameFile "`pwd`" Last edited by ephemera; 15th August 2008 at 07:15 AM. |
|
|||
![]()
Ephemera, the [2003] is a shell regular expression, which will never match the string "2003".
Code:
$ mkdir test && cd test $ pwd /home/j65nko/test $ for NUM in 0 1 2 3 4 ; do touch Street_${NUM} ; done $ ls -l total 0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_1 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_2 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_3 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_4 $ touch Street_\[2003\] $ ls -l total 0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_1 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_2 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_3 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_4 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:35 Street_[2003] $ ls -l Street_[2003] -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_2 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_3 $ ls -l Street_[023] -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_0 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_2 -rw-r--r-- 1 j65nko j65nko 0 Aug 15 03:34 Street_3 ![]()
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
![]() Quote:
$ ls -l "Street_[2003]" notice that it works with the quotes (as it does in the script). now, with regards to the errors OP got: Code:
chmod: /home/share/music/mp3/151/Code_Of_Tha_Street_[2003]/*: No such file or directory # empty directory $ mkdir "Street [2003]" # OP's script will do $ chmod uog-x "Street [2003]/*" Last edited by ephemera; 15th August 2008 at 09:15 AM. |
|
||||
![]() Quote:
Code:
for fileName in $1/*
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
||||
![]() Quote:
Ok, now i will present my line of reasoning: First note that $1/* in the for statement correctly globs the dir. Run the following to convince yourself: $ mkdir test $ touch "test/Street [2003]" $ export d=test $ for f in $d/* ; do echo "$f" ; done Now, lets take this error as an example: Code:
chmod: /home/share/music/mp3/151/Code_Of_Tha_Street_[2003]/*: No such file or directory we then enter the for loop where the dir Code Of Tha Street [2003] is converted to Code_Of_Tha_Street_[2003] (unless ofcourse those were underscores to begin). Next, RenameFile() is called with Code_Of_Tha_Street_[2003] and the for loop entered with $fileName="Code_Of_Tha_Street_[2003]/*" chmod uog-x "$fileName" will now generate the given error. I have had enough of this discussion and I will have nothing more to say on this thread. Last edited by ephemera; 15th August 2008 at 04:38 PM. |
|
||||
![]()
Sorry that i haven't replied to any of your post, yet
We (ppl who live in my region) have some important problems here, where i live.... that we (some volunteers try to resolve), we're collecting signatures against local project... so i ain't got time to fallow this thread yet... Will read everything in few days... when this is over |
|
||||
![]() 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 ' []' '_()') echo " $newFileName" 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` Not the best solution, but it'll help me avoid problems later I know it looks dirty atm, i will fix it ![]() Thanks for replies EDIT: fixed ugly code, more later Edit2: Code:
#!/bin/sh RenameFile() { for fileName in $1/* do newFileName=$(echo "$fileName" | tr ' []' '_()') echo " "$newFileName if [ "$fileName" != "$newFileName" ] then mv -f "$fileName" "$newFileName" fi if [ -d "$newFileName" ] then RenameFile "$newFileName" else chmod uog-x "$newFileName" fi done } find `pwd` -name "*.jpg" -delete find `pwd` -name Thumbs.db -delete find `pwd` -name "*.ini" -delete RenameFile `pwd` Last edited by graudeejs; 17th August 2008 at 03:53 PM. |
|
||||
![]()
OK, i found good reason for that....
. gives only relative paths But if i want to use mplayer in slave mode and control it with menus...., then absolute path is way better to be used So here are my 2 scripts rmwinshit.sh mkplaylists.sh They work fine, but i'd be glad if someone could give me some suggestions, as this was ugly and hard way to make it work.... and i bet there is a better way.. mkplaylists.sh is supposed to read subdirectories in given folder and output playlists in /home/share/music/playlsts/ might be problems if you start script and have less than 2 subdirs rmwinshit.sh removes all/most crap that you get when you get when you copy files from ntfs/msdosfs to ufs/ext2fs and friends It also replaces some problematic characters: Code:
space ==> _ [ ==> ( ] ==> ) Last edited by graudeejs; 18th August 2008 at 10:33 PM. |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Crontab won't run script | Petrocelli08 | FreeBSD General | 4 | 7th March 2009 04:19 AM |
Backup script(s)? | giddyupman | General software and network | 2 | 3rd January 2009 02:06 PM |
Handy X11 script | Gabe_G23 | Guides | 6 | 25th October 2008 05:08 PM |
Automation Script | ninjatux | FreeBSD General | 2 | 24th October 2008 04:16 PM |
Shell Script. | bsdnewbie999 | Programming | 21 | 15th July 2008 07:54 AM |