Answer the question
In order to leave comments, you need to log in
How to rename files in a directory?
Hello.
In any folder, using C ++, you need to rename all the files according to a certain rule. How to get filename and change it?
OS: Windows 8.1
Answer the question
In order to leave comments, you need to log in
TSearchRec Search;
AnsiString Path = "C:\\Windows";
if (FindFirst(Path + "\\*", faDirectory, Search) == 0) {
do {
if
(Search.Name == "." || Search.Name == ".." )
continue;
if (Search.FindData.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY) {
// Если это папка
//
}
else {
//копируем файл с новым именем
CopyFile((Path+"\\"+Search.Name).t_str(),(Path+"\\"+newName).t_str(), 0);
//Удаляем файл со старым именем
//Запоминаем путь к файлу, который нужно удалить и после того как освободим Search удаляем.
};
}
while (FindNext(Search) == 0);
FindClose(Search);
};
or use OS commands.
or so you can:
#include <stdio.h>
rename (char *oldname, char *newname); /* ANSI */
Remaining within the framework of the standard (C++03, C++11 or the upcoming C++1y) it is impossible to get the name of already existing files.
You have many libraries to choose from, the most famous are Qt and boost
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question