MathGroup Archive 2006

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

Search the Archive

RE: How to change file names?

  • To: mathgroup at
  • Subject: [mg70882] RE: [mg70819] How to change file names?
  • From: "David Annetts" <davidannetts at>
  • Date: Mon, 30 Oct 2006 05:33:22 -0500 (EST)


> 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?

You need StringReplace[] in some form ....

	iname = StringJoin["Old_Name", ToString[#], ".jpg"] & /@ Range[10]
	oname = StringReplace[#, {"Old" -> "New"}] & /@ iname

If you are only renaming files, then you don't need to Import the files.
You only need RenameFile[].



  • Prev by Date: Re: Re: Wolfram Workbench
  • Next by Date: Advanced nonlinear integro-differential equation
  • Previous by thread: Re: How to change file names?
  • Next by thread: old recursive polynomial set into matrices