목표 : 작업폴더내 모든 파일명 앞에 현재 날짜 년 월 일  이 붙도록 하는 콘솔 프로그램

단계 :

폴더 경로 얻기 -> 폴더 경로 내의 파일 검색 -> isDot  - no -> 파일명 수정 -> next

  - yes-> next



1. 폴더 (Directory) 경로 얻기


함수 : GetCurrentDirectory



2. 폴더내 파일 검색


struct _finddata_t cfile;

long hFile;



if( (hFile = _findfirst( "*.*", &c_file )) == -1L )

printf( "No files in current directory!\n" );

else

{

/* Find the rest of the .c files */

do

{

  // 작업

     }while( _findnext( hFile, &c_file ) == 0 );


_findclose( hFile );

}









3. isDot ?


콘솔로 폴더를 검색하면 상위 폴더를 보는 . 과 .. 이 있기때문에 이를 걸러주어야함.

if(!strcmp(".", c_file.name)) _findnext( hFile, &c_file );

if(!strcmp("..", c_file.name)) _findnext( hFile, &c_file );




4. 시스템 시간 얻기

SYSTEMTIME 을 이용하는 방법, time_t를 이용하는 방법이 있는데, 

time_t는 뭔가 부정확한 느낌이다.





5. 파일명 바꾸기.


rename 함수를 이용한다

rename("기존 파일명 (경로포함)" , "바뀔 파일명(경로포함);














+ Recent posts