[ask rename file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
hellow all
i have some problem for rename file
this my c++
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <time.h>
#include <string>
using namespace std;
int main () {
//chek_date
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%Y%m%d",timeinfo);
//open sample file for loop
const int size = 80;
char outas[ size ];
ifstream infile;
infile.open ("sample");
while (!infile.eof()){
//cout << (outas) infile.get();
getline(infile,outas);
//rename(outas,outas+"_"+buffer);
cout<<(outas+"_"+buffer);
infile.close();
}
return 0;
|
where sample is dump list of file (iam using ls -1 *.txt >sample) for looping file
1 2 3
|
jakarta.txt
bandung.txt
semarang.txt
|
so i want rename this file with append date
and file will like output
1 2 3
|
jakarta_yyyymmdd.txt
bandung_yyyymmdd.txt
semarang_yyyymmdd.txt
|
i need your advice
thx before
¿What issues are you having?
You shouldn't loop on eof()
@ne555
thx for your comment
actualy i just want rename jakarta.txt to jakarta_yyyymmdd.txt same with bandung and semarang where yyyymmdd is time now
I know what you want.
I ask about the problem.
By instance, your code doesn't compile, so you ought to post the compiler messages
Topic archived. No new replies allowed.