Robizzle wrote:[color=blue]
> I'm trying to write a simple console app that will rename all the files
> in a directory according to any rules supplied by a user during
> runtime. For example rename all *.jpg to *.jpeg. My problem is
> getting a list of all the files that are in the current directory. The
> only way I could figure out how to do it is to loop through all the
> possible file names and checking if each one exists, if it does then
> i'd push it's name into a queue for later processing.
>
> But it seems like there has to be a better way. Are there any standard
> functions that will return a list of all the file names that are in a
> directory, or allow me to access files one by one until there are no
> more?
>
> I'm planning to mainly use this program in windows, however, if it is a
> huge hassle, I could teach myself shell scripts and go that route as
> the files I need to rename are very small and I have access to several
> linux machines.
>
> Thanks in advance for any help, I've tried several searches and don't
> see anything relavant.
>
> -Rob[/color]
If you use csh in unix or cygwin, you can do something like this from
the command prompt:
foreach f (*.jpg)
mv $f `echo $f | cut -d. -f1`.jpeg
end
It assumes there are no dots in the filenames.
As for a C++ solution, you might consider the Boost.Filesystem library:
http://boost.org/libs/filesystem/doc/index.htm
Cheers! --M