delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/06/15:40:53

X-Spam-Check-By: sourceware.org
Message-ID: <31b7d2790704061240y10ae5e4fw5e2d4a2bfc427aa@mail.gmail.com>
Date: Fri, 6 Apr 2007 14:40:31 -0500
From: "DePriest, Jason R." <jrdepriest AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Renaming gotcha under FAT file system
In-Reply-To: <gs7d13hee0eaqmm9ltbqvphj7hpagu4m4i@4ax.com>
MIME-Version: 1.0
References: <gs7d13hee0eaqmm9ltbqvphj7hpagu4m4i AT 4ax DOT com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 4/6/07,  wrote:
> My Bash script renames file and folders from regular expression patterns found in a preset file. The
> patterns allow for complex renaming, yet sometimes it just converts the file name to title case. The
> script produces a separate file for executing the rename commands.
>
> printf "mv %-200s \"%s\"\n" "-f \"$DIR/"$FILE"\"" "$DIR"/"$NEWNAME" >> doit.sh
>
> The typical command in the doit.sh file looks like the following line.
>
> mv -f "file_to_be_rename.ext" "File_To_Be_Rename.ext"
>
> The secondary script renames hundreds of files. Twenty percent may fail do "mv" encountering the
> same file name (similar to the line above).
>
> Question: How do you force mv to rename a file with the same filename? The code above returns an
> error that the files are the same.
>
> I prefer using mv since my cygwin installation does not contain rename or mmv. Portability is very
> important for this script. Apparently, Wintel file systems are case insensitive, which create a
> problem for this script.  Please give me some suggestions on dealing with this scenario. Script
> examples on creating a temp file or logic that appends an extra character would help me a good deal.
>
>
> --

I handled this issue by first renaming the file to some temporary name
and then naming it back to its original name in the case I want.

So you would store the original filename in a variable, rename the
file to some temp name, run your magic on the original filename, then
rename the temp file to the newly fixed filename.

I can't find my perl script or I would post sample code.

-Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019