LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2006, 10:42 AM   #1
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
rename script won't change uppercase to lowercase on fat32


I'm not sure if the reason it's not working is because it's a fat32 partition, but it seems to work ok on the reiserfs partitions I've got. This is the script:
Code:
#! /bin/sh

# converting space to underscores ({i// /_}) and uppercase to lowercase 
# (tr "[:upper:]" "[:lower:]")

for i in *
do mv "$i" "$(echo ${i// /_} | tr "[:upper:]" "[:lower:]")"
done
if I try a manual mv, I get the same error:
Code:
mv: cannot move `Summer_2002' to a subdirectory of itself, `summer_2002/Summer_2002'
for a directory, and
Code:
mv: `Seignosse 001.avi' and `seignosse 001.avi' are the same file
for a file.

Is this because it's fat32? Is there any way around this?

edit: http://www.linuxquestions.org/questi...d.php?t=160202 this thread seems to suggest that it's a problem with the way the partition is mounted?

Last edited by pwc101; 09-27-2006 at 10:45 AM.
 
Old 09-27-2006, 11:05 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Too my knowledge FAT32 (MS based) does not distinguish between upper and lowercase. So this seems to be a FS type problem.

Maybe this will help to explain in more detail: FAT

It doesn't help, but hopefully it clears things up a bit.
 
Old 09-27-2006, 11:17 AM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Yes druuna fat32 does not make any distiction between upper and lowercase file names. NTFS does but thats because its a non dos filesystem. This is indeed a file system limitation.
 
Old 09-27-2006, 11:26 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Original Poster
Rep: Reputation: 128Reputation: 128
from that other thread I found, it seems that if you mount the drive in a particular manner, it's possible to get it to distinguish between upper and lowercase. This is the reply to the OPs question in the other thread (by the OP I might add!...):

none /mnt/win_f supermount dev=/dev/sda1,fs=vfat,--,shortname=win95,umask=0,codepage=850,iocharset=iso8859-1,kudzu 0 0

I'm not exactly sure what it's supposed to be, but it looks suspiciously like an fstab entry to me... any thoughts?
 
Old 09-27-2006, 05:16 PM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Original Poster
Rep: Reputation: 128Reputation: 128
ok, I've had an idea.

I can tell it to rename a file called "Test" to "Test.temp" without it complaining. Ok, good. I can then tell it to rename that "Test.temp" file to "test" (note lowercase first letter), and it holds the case. It seems that only by going through this intermediate stage of calling it something different can I get it to rename a file to lowercase letters.

So, with that in mind, I've tried the following:
Code:
#! /bin/sh

# testing some ideas for renaming scripts...

# remove all spaces from the filenames first
for i in *
        do mv "$i" "${i// /_}"
done

# create a list of the directory contents, and turn it into a lowercase file list
ls -1 $PWD | tr "*/" " " | tr "A-Z" "a-z" > $PWD/list

# then rename all the folders in the current directory to original_name.temp
for i in $PWD/*
        do mv "$i" "$i.temp"
done

# then, rename the files called original_name.temp to the lowercase name from the list file
#for i in `ls -1 | tr "*/" " "`
#       do mv "$i" "$(cat list.temp)"
#done

# try to rename the files from the list.temp file using a foreach loop
#for i in *
#       do foreach j=`cat list.temp`
#               mv "$i" "$j" 
#       done
#done

# or create a new variable which contains the list of the cat'ed list.temp. 
# For this, you'll need two loops
#for i in *
#       for j in `cat list.temp`
#       do mv "$i" "$j"
#       done
#done

# multiple do's within a for...
for i in *
        do NAME=`cat list.temp` && {
                mv $i $NAME
        }
done
what I'm trying to do is use the contents of a file (list.temp) as the input for the mv command i.e. the new filename. However, what happens when I cat the contents of list.temp in the loop is the first file the for loop comes across gets renamed to all the files in the list, so rather than having say 10 individial file, I get one file renamed with all 10 original filnames, separated by \n. I can't for the life of me figure out how to get it to just use one line of the list.temp file for each cycle through the loop.

I thought maybe a "while" might need to be involved at some point...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UPPERCASE to lowercase command? pk21 Linux - General 4 06-12-2007 10:26 AM
Uppercase filenames showing in lowercase rvoigt Linux - General 1 02-20-2006 11:07 PM
Converting Uppercase to Lowercase AMMullan Linux - Software 6 10-18-2005 07:32 PM
External harddrive FAT32- VFAT options (uppercase to lowercase file name translation) pauquetb Linux - General 1 03-20-2004 12:52 PM
Converting lowercase to uppercase noodle123 Programming 1 05-17-2002 02:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration