1

My goal is to build a program that renames all files in the current working directory so they don't have any spaces, any special characters or any accented characters (for example É would become E). I'm planning on using int rename(const char *oldname, const char *newname); . My problem is how do I get the files in the current working directory? I would like to have the executable I'm creating put in a folder with a files with bad names and run it and the files all be renamed.

A platform independent solution would be preferable, otherwise I'm using Windows 7 Enterprise 32bit.

This question isn't a duplicate because I don't know the path for opendir ("c:\\src\\"); it's whatever directory the program is being executed from.

Celeritas
  • 14,489
  • 36
  • 113
  • 194
  • 2
    `boost::filesystem` has a `directory_iterator` or something. – chris Aug 15 '12 at 00:10
  • 1
    http://stackoverflow.com/questions/612097/how-can-i-get-a-list-of-files-in-a-directory-using-c-or-c – Duck Aug 15 '12 at 00:11
  • I was confused because I thought I had to use the Boost library but I red in this question it had been deprecated. http://stackoverflow.com/questions/6108650/replacement-for-deprecated-boost-filesystem-initial-path So no need for boost? – Celeritas Aug 15 '12 at 04:11
  • @Celeritas Boost.Filesystem hasn't been deprecated. The question is about one particular function that has been deprecated. Use Boost.Filesystem, it's far easier to use than the other ways. – Sebastian Redl May 15 '15 at 22:50

2 Answers2

1

Here's a sample code to do that:

http://bytes.com/topic/c/answers/869208-list-files-directory

In essence you utilize these APIs: FindFirstFile and FindNextFile

For cross-platform solution see findfirst() and findnext()

YePhIcK
  • 5,816
  • 2
  • 27
  • 52
0

An option is to use opendir(".") , this will open the current directory.

Peter
  • 35,646
  • 4
  • 32
  • 74
mohRamadan
  • 571
  • 6
  • 15
  • It looks that the current C++ standard has no convenient interface for reading all files in a directory. Future version should add this functionality. The unix system has all the C interfaces for dealing with filesystems. Unix actually is very good at this with the abstraction of File to represent all filesystem objects. – Kemin Zhou Jan 04 '17 at 20:33