• Post Reply Bookmark Topic Watch Topic
  • New Topic

file renamer project  RSS feed

 
osgaldor Storm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've had a project I've needed to build for several years now and I just don't know what objects and methods I need in order to build it. I want to be able from the command line in win 7 to cd into a directory and run a java program that will take each file in the directory (of image files) and rename them based on a simple text string pattern-- for example in my directory of photos from my trip to Thailand I want to invoke a program that will count the number of images in the current directory and then rename them all to something like thailand_01, etc. with the numbers automatically incrementing. I have no idea how to even tell the program to run through all the files in the directory and count them, let alone do the rename while plugging in the correct name with the number. If you can point me in the right direction of what classes and methods I need in order to be able to do this, I'd be very grateful.

So after cd'ing into the dir I need I want to be able to run a command like the following: java renamer all thailand_# and have it then go through each file in the dir and rename it with that name appended with the item number, all while keeping the existing file extension.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class java.io.File has methods to list the files and subdirectories in a directory and to rename files.

Class java.lang.String has lots of methods to look at what's inside strings. If you want to do more complicated things with patterns, you could use a regular expression - you'll want to use the classes java.util.regex.Pattern and java.util.regex.Matcher.
 
Utha Ramadhan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hope this can help, btw im using java7
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Utha,

We try not to give complete code examples here but instead coach the poster towards their own answer. A code fragment is fine to illustrate a point.
 
osgaldor Storm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both, Jesper and Utha! Very helpful. I'm inclined to mark this resolved.
 
Utha Ramadhan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whoa sorry and thank you btw
 
osgaldor Storm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Utha!
You gave me what I needed. I can take your code example and mod it to my needs. Mission Accomplished!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!