목록(텍스트 Editor) 내 모든 파일을 1개씩 가져와 텍스트 범위(시작 ~ 끝)를 찾고 앞, 뒤에 기호('[', ']')를 삽입한 후 다시 Editor로 기록하는 샘플 코드입니다.

원본 이름 수정 이름
*123_테스트_321*.txt *[123_테스트_321]*.txt

* 파일명 내 속성 태그(<...>) 수정 주의

* 확장명 수정 시 사용할 수 없게 될 수 있으므로 주의

//  파일 개수를 얻는다.
var count = getFileCount();
if (0 == count) {
    alert("이름을 변경 할 파일이 없습니다.");
    return;
}

//  진행바 범위를 설정한다.
setProgressRange(0, count);

//  진행바를 화면에 보인다.
showProgress(true);

//  범위로 찾을 텍스트를 설정한다.
var beginStr = "123", endStr = "321";

//  파일 개수 만큼 파일명을 변경한다.
for (index = 0; index < count && !isStop(); )
{
    //  지정한 인덱스의 파일명을 얻는다.
    var fileName = getFileName(index);

    //  이름과 확장명을 분리한다.
    var array = splitPath(fileName);

    /*파일명을 변경한다.*/
    var begin = array[1].indexOf(beginStr);
    if (-1 != begin)
    {
        var end = array[1].indexOf(endStr, begin);
        if (-1 != end)
        {
            end += endStr.length;
            //	앞, 뒤에 삽입할 기호([, ])는 변경할 수 있습니다.
            array[1] = array[1].substring(0, begin) + "[" + array[1].substring(begin, end - begin) + "]" + array[1].substring(end);
        }
    }

    // 파일명을 기록한다.
    setFileName(index, array[1/*이름*/] + array[2/*확장명*/]);

    // 진행바의 위치를 갱신한다.
    setProgress(++index);
}

// 작업 완료 메시지를 출력한다.
alert("파일명 변경이 완료됐습니다.");

// 진행바를 숨긴다.
showProgress(false);

목록(텍스트 Editor) 내 모든 파일을 1개씩 가져와 텍스트를 이름 뒤에서부터 찾고 뒷부분 텍스트를 삭제 후 다시 Editor로 기록하는 샘플 코드입니다.

원본 이름 수정 이름
주간계획서 제출 1231.xlsx
1부서 주간계획서 제출입니다 1231.xlsx
12월 2주차 주간계획서 제출 1230.xlsx
3월말 부터 12월까지 주간계획서 제출 20221229.xlsx
주간계획서 제출 1231.xlsx
1부서 주간계획서 제출입니다 1231.xlsx
12월 2주차 주간계획서 제출 1230.xlsx
3월말 부터 12월까지 주간계획서 제출 20221229.xlsx

* 파일명 내 속성 태그(<...>) 수정 주의

* 확장명 수정 시 사용할 수 없게 될 수 있으므로 주의

//  파일 개수를 얻는다.
var count = getFileCount();
if (0 == count) {
    alert("이름을 변경 할 파일이 없습니다.");
    return;
}

//  진행바 범위를 설정한다.
setProgressRange(0, count);

//  진행바를 화면에 보인다.
showProgress(true);

//  찾을 텍스트를 설정한다.
var findStr = "계획서 제출";

//  파일 개수 만큼 파일명을 변경한다.
for (index = 0; index < count && !isStop(); )
{
    //  지정한 인덱스의 파일명을 얻는다.
    var fileName = getFileName(index);

    //  이름과 확장명을 분리한다.
    var array = splitPath(fileName);

    /*파일명을 변경한다.*/
    //  이름 끝에서부터 찾고 뒷부분 텍스트는 사용하지 않는다.
    var end = array[1].lastIndexOf(findStr);
    if (-1 != end)
    {
        array[1] = array[1].substring(0, end + findStr.length);
    }

    // 파일명을 기록한다.
    setFileName(index, array[1/*이름*/] + array[2/*확장명*/]);

    // 진행바의 위치를 갱신한다.
    setProgress(++index);
}

// 작업 완료 메시지를 출력한다.
alert("파일명 변경이 완료됐습니다.");

// 진행바를 숨긴다.
showProgress(false);

안녕하세요.

쉽고 편리한 파일명 편집(일괄 변경) 소프트웨어 EasyRenamer 의 사용 방법을 설명합니다.

 

EasyRenamer는 JavaScript 프로그래밍 언어(ECMAScript 5 지원)로 파일명을 수정할 수 있습니다.

파일명 수정에 필요한 미리 정의된 스크립트 함수를 설명합니다.

 

1. Editor & 파일명 관련

이름 함수명 인자 반환 값
파일 개수 조회 getFileCount     integer
파일 추가

addFiles path string integer
// 중복된 파일을 생략하고 폴더 내 파일을 모두 추가한다.
var count = addFiles("c:\\temp\\movies");

// 파일 1개를 추가한다. 중복된 파일이면 반환 값은 0 이다.

var count = addFiles("c:\\temp\\movies\\비디오.mp4");
파일 목록 초기화 clearAllFiles      
실행 취소 이력 초기화 emptyUndo      
파일명 1개 읽기

getFileName index integer string
// 목록 내 첫번째 파일의 경로를 얻는다.
var path = getFileName(0);
파일명 1개 쓰기

setFileName index integer  
newFileName string
// 목록 내 첫번째 파일 경로를 얻고 [0]디렉터리 경로 [1]이름 [2]확장명으로 분해한다.
var path = getFileName(0);
var array = splitPath(path);

// 파일명을 수정한다.

array[1] += "_테스트";

// 수정된 파일명을 목록에 출력한다.

setFileName(0, array[0] + "\\" + array[1] + array[2];
파일명 N개 읽기 getFileNames index integer JSON array
count integer
파일명 N개 쓰기 setFileNames index integer  
newFileNames JSON array
파일 속성 읽기 getProperty index integer string
name string
파일 경로 분리 splitPath path string string array

2. 파일 I/O 관련

이름 함수명 인자 반환 값
폴더 내 파일 목록 조회 getFiles path string JSON array
파일 유무 검색 existFile path string bool
파일 삭제 deleteFile path string bool
파일 이동 moveFile sourcePath string bool
destPath string

3. 시스템 관련

이름 함수명 인자 반환 값
프로그램 실행 createProcess fileName string integer
arguments string
프로그램 강제 종료 kill processId integer bool
모든 프로그램 강제 종료 killAll      
프로세스 종료 대기 waitForExit processId integer integer
timeout integer
마지막 에러 조회 getLastError     string

4. 콘솔(Console) 윈도우 & 파일 로그

이름 함수명 인자 반환 값
콘솔 초기화 clearConsole      
콘솔 윈도우 보기 / 숨기기 showConsole isShow bool  
콘솔 텍스트 출력 console message string  
로그 파일 생성(열기) openLog path string bool
isCreate bool
로그 기록 log log string bool
로그 파일 닫기 closeLog     bool

5. 진행바(Progress bar)

이름 함수명 인자 반환 값
진행바 범위 설정 setProgressRange min integer  
max integer  
진행바 보기 / 숨기기 showProgress isShow bool  
진행바 위치 값 설정 setProgress pos integer  

 

목록(텍스트 Editor) 내 모든 파일을 1개씩 가져와 수정한 후 다시 Editor로 기록하는 샘플 코드입니다.

* 파일명 내 속성 태그(<...>) 수정 주의

* 확장명 수정 시 사용할 수 없게 될 수 있으므로 주의

//  파일 개수를 얻는다.
var count = getFileCount();
if (0 == count) {
    alert("이름을 변경 할 파일이 없습니다.");
    return;
}

//  진행바 범위를 설정한다.
setProgressRange(0, count);

//  진행바를 화면에 보인다.
showProgress(true);

//  파일 개수 만큼 파일명을 변경한다.
for (index = 0; index < count && !isStop(); ) {
    var extension = "";
    //  지정한 인덱스의 파일명을 얻는다.
    var fileName = getFileName(index);

    //  이름과 확장명을 분리한다.
    var dot = fileName.lastIndexOf(".");
    if (-1 != dot) {
        extension = fileName.substring(dot);
        fileName = fileName.substring(0, dot);
    }

    /*파일명을 수정한다.*/

    //  파일명을 기록한다.
    setFileName(index, fileName + extension);

    //  진행바의 위치를 갱신한다.
    setProgress(++index);
}

//  작업 완료 메시지를 출력한다.
alert("파일명 변경이 완료됐습니다.");

//  진행바를 숨긴다.
showProgress(false);

목록(텍스트 Editor)의 파일을 모두 제거하고 실행 취소(Undo) 이력을 초기화하는 샘플 코드입니다.

// 에디터 내 모든 파일을 제거한다.
clearAllFiles();

// 모든 실행 취소(Undo) 이력을 초기화한다.
// 메인 윈도우 [실행 취소] 버튼이 Disable 된다.
emptyUndo();

+ Recent posts