遍历文件夹下文件 打印创建时间 并按创建时间排序 然后按时间每隔一秒发送给pacs服务器(自动化模拟CT部分代码)

直接上代码:

#include
#include
#include
#include
#include
#include
#include "fstream"  
#include
#include
#include
#include
#include
#define fileNumber 4000
using namespace std;

 
int main( void )
{
/*    struct stat buf;
    int result;
 
    //获得文件状态信息
 
    result =stat( "/home/jjkj/CTdevice", &buf );
 
    //显示文件状态信息
 
   if( result != 0 )
       perror( "显示文件状态信息出错" );//并提示出错的原因,如No such file or directory(无此文件或索引)
 
    else
    {
 
                printf("文件大小: %d\n", buf.st_size);
        printf("文件创建时间: %s", ctime(&buf.st_ctime));
        printf("访问日期: %s", ctime(&buf.st_atime));
        printf("最后修改日期: %s", ctime(&buf.st_mtime));
     
    }*/
    struct stat buf;
    int result;
    printf("1");
    vector fileCTime;
    printf("2");
    //long fileCTime[2000];
    int j;
    
    for(j=0;j     {
       // fileCTime[j]=0;
       fileCTime.push_back(0);
    }
    j=0;
    
    
    DIR * dir;
    struct dirent * ptr;
//    char file_list[100][40];
    int i=0;
    char srcFile1[fileNumber][100];
  //  string rootdirPath = "/home/jjkj/CTdevice";
    string rootdirPath = "/home/jjkj/data";
    char * mid;
    char   time[25];
    //char timer[9];
    char* timer=new char[9];
    string x;
    string dirPath;
    const char* constc = nullptr;         //初始化const char*类型,并赋值为空
    dir = opendir((char *)rootdirPath.c_str()); //打开一个目录
    while((ptr = readdir(dir)) != NULL) //循环读取目录数据
    {
        printf("***********************************************************************************************\n");
        printf("d_name : %s\n", ptr->d_name); //输出文件名
        x=ptr->d_name;
        dirPath = rootdirPath+"/" + x;
        constc= dirPath.c_str();
        result =stat( constc, &buf );
        printf("d_path : %s\n", dirPath.c_str()); //输出文件绝对路径 //  
      
        if( result != 0 )
        perror( "显示文件状态信息出错" );//并提示出错的原因,如No such file or directory(无此文件或索引)
 
        else
        {
 
           printf("文件大小: %d\n", buf.st_size);
           printf("文件创建时间: %s\n", ctime(&buf.st_ctime));
           mid=ctime(&buf.st_ctime);
           strcpy(time,mid);
           timer[0]=time[8];
           timer[1]=time[9];
           timer[2]=time[11];
           timer[3]=time[12];
           timer[4]=time[14];
           timer[5]=time[15];
           timer[6]=time[17];  
           timer[7]=time[18];
           timer[8]='\0';
          // const char *nptr=timer;
           long  intTime=atol(timer);//days hours minutes seconds
           fileCTime[j]=intTime;
           printf("文件创建时间: %ld\n",intTime);
           //printf("访问日期: %s", ctime(&buf.st_atime));
           //printf("最后修改日期: %s", ctime(&buf.st_mtime));
     
        }
        //printf("***********************************************************************************************\n");
        x = dirPath.c_str();
        strcpy(srcFile1[i],dirPath.c_str()); //存储到数组
        j++;
        if ( ++i>=fileNumber )
        {
            
            break;   
        }
    }
    delete [] timer;
    closedir(dir);//关闭目录指针
    printf("the j is %d\n",j);
    printf("the i is %d\n",i);
    long t;
    char ch[100];
    
//    for(int ii=0;ii  //   {
  //      printf("the time is: %d\n",fileCTime[ii]);
   //     printf("the path is: %s\n", srcFile1[ii]);
 //   }
    
    
    
    for(int ii=0;ii     {
        for(int jj=0;jj         {
            if(fileCTime[jj]>fileCTime[jj+1])
            {
                t=fileCTime[jj];
                fileCTime[jj]=fileCTime[jj+1];
                fileCTime[jj+1]=t;
                
                //char* ch=new char[strlen(srcFile1[jj])];
                
                strncpy(ch,srcFile1[jj],strlen(srcFile1[jj]));
                memset(srcFile1[jj],'\0',100);
                strncpy(srcFile1[jj],srcFile1[jj+1],strlen(srcFile1[jj+1]));
                memset(srcFile1[jj+1],'\0',100);
                strncpy(srcFile1[jj+1],ch,strlen(ch));
                memset(ch,'\0',100);
                //delete [] ch;
            }
        }
    }
    string server="storescu 192.168.1.114 104 ";
    string port=" -aec ACME_STORE -aet UIHCT -d --required --propose-lossless";
    string file="CT_5d083a70a0da190b.dcm";
    string strr;
    const char* comm=nullptr;
    
    for(int ii=0;ii     {
       usleep(1000000);
       printf("the time is %d\n",fileCTime[ii]);
       printf("the path is %s\n", srcFile1[ii]);
       printf("the ii is %d\n", ii);
       strr=server+srcFile1[ii]+port;
       comm=strr.data();
       system(comm);
    }
    
    
    
    
    
    return 0;
 
}

你可能感兴趣的:(dcm,自动化模拟CT)