Changing file extensions.....

The flash disk contents are in a folder named “flash-disk”. Please help me create a program that can visit each folder and its subfolders in the “flash-disk” and rename all “.lhs” files to “.txt”. Once done, display how many folders were visited and how many affected files were fixed by your program
.
Thank you
Last edited on
yea just call rename

but if you don't have C++17's filesystem, there is no way to go through all the files without knowing the name, maybe if the filenames had sequential numbers on them you could guess.
Last edited on
Did you try doing an internet search? A few moments, a couple of search terms and I found lots of links for getting lists of files and how to rename them.

https://stackoverflow.com/questions/40529365/how-to-change-the-extension-of-a-file

www.cplusplus.com/reference/cstdio/rename/

Renaming a file name/extension is easy, if the name is known. Searching directories for specific file extensions:

https://stackoverflow.com/questions/11140483/how-to-get-list-of-files-with-a-specific-extension-in-a-given-folder
A changeextension.h should only consist of function declaration and changeextension.cpp should contain the definitions of those function in the changeextension.h
THE MAIN FILE SHOULD ONLY CONTAIN CALLS TO THOSE FUNCTIONS.

What functions? Your instructions are not clear at all.
How does your code get to know the names of the files to be changed?

The assignment will be easy if the user types in "./myrenametool *.lhs", where the shell does all the necessary filename globbing(*1), and you get all the filename in argv.
1
2
3
4
5
int main ( int argc, char *argv[] ) {
  for ( int c = 1 ; c < argc  ; c++ ) {
    renameit(argv[i]);
  }
}


But if your argv[1] is the name of a directory, and you're expected to find for yourself all the *.lhs files, then things are going to get tricky in a hurry (unless you have C++17 as poteto mentions).




(*1)M$ of course makes this simple task unnecessarily complicated.
http://anadoxin.org/blog/enabling-globbing-in-a-console-win32-application.html
Topic archived. No new replies allowed.