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
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.
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.
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).