Unix iTOps Tube

Monday, May 7, 2012

[ask]rename file


Code:


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


Code:


jakarta.txt

bandung.txt

semarang.txt


so i want rename this file with append date

and file will like output


Code:


jakarta_yyyymmdd.txt

bandung_yyyymmdd.txt

semarang_yyyymmdd.txt


i need your advice

thx before




No comments:

Post a Comment