Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to change file names?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70853] Re: How to change file names?
  • From: bghiggins at ucdavis.edu
  • Date: Sat, 28 Oct 2006 23:39:55 -0400 (EDT)
  • References: <ehv9b5$gav$1@smc.vnet.net>

Use Rename.

Suppose your files are in a given directory. Then set the directory
containing the files to the current directory. For my case on Mac OS X
I would evaluate

SetDirectory["/Users/brian/Desktop/BGHtestFolder"]

Here is a list of file names

ls=FileNames[]


{BGH1.jpg,BGH2.jpg,.DS_Store}

 Note the DS_Store is a file crated by the Mac OS X for each directory.
In the Rename operation below I delete this file from the list to be
renamed

Then I use Rename

Map[RenameFile[#,StringReplace[#,"jpg"->"JPEG"]]&,Drop[ls,-1]]


{BGH1.JPEG,BGH2.JPEG}


Cheers,

Brian

solidifire wrote:
> There are n JPEG files, with file names f1, f2, ..., fn.
> I want to change their names to, for example, g1, g2, ..., gn.
> Of course the easiest way is to change file names by myself,
> but this is not convenient when n is large.
> How should I do by using Mathematica?
> I tried:
>
> Export["g1.jpg",
>   Import["f1.jpg", "JPEG"], "JPEG"]
>
> It does change the file name as I expect.
> There is, however, a side effect:
> somehow the file size in bytes of g1.jpg is one-tenth of that of
> f1.jpg.
> Besides, I have to read in the files and then write out the files
> -- I don't think these two steps are really necessary,
> because all I want to do is to change the file names.
> Is there any better method?
> Thank you in advance.


  • Prev by Date: Re: Searching for a function
  • Next by Date: Re: Modify a list of pure functions
  • Previous by thread: Re: How to change file names?
  • Next by thread: RE: How to change file names?