파일명 포맷에 접미사 기능 추가
This commit is contained in:
@@ -95,7 +95,6 @@ function register() {
|
||||
ipcMain.handle('rename-files', async (_event, { folderPath, files, prefix, digits, postfix = '' }) => {
|
||||
const errors = [];
|
||||
const pad = (n) => String(n + 1).padStart(digits, '0');
|
||||
const suffix = postfix ? `_${postfix}` : '';
|
||||
|
||||
// 1단계: 임시 이름으로 이동 (충돌 방지)
|
||||
const tmpMap = [];
|
||||
@@ -114,7 +113,7 @@ function register() {
|
||||
// 2단계: 최종 이름으로 이동
|
||||
const renamed = [];
|
||||
for (const { tmp, ext, idx } of tmpMap) {
|
||||
const newName = `${prefix}_${pad(idx)}${suffix}${ext}`;
|
||||
const newName = `${prefix}${pad(idx)}${postfix}${ext}`;
|
||||
const dest = path.join(folderPath, newName);
|
||||
try {
|
||||
fs.renameSync(tmp, dest);
|
||||
|
||||
@@ -69,7 +69,7 @@ export function createFolderController({
|
||||
setStatus(`${state.files.length}개 파일 로드됨`, true);
|
||||
|
||||
const folderName = folder.replace(/\\/g, '/').split('/').pop();
|
||||
if (folderName) inputPrefix.value = folderName;
|
||||
if (folderName) inputPrefix.value = `${folderName}_`;
|
||||
|
||||
renderGrid();
|
||||
updatePreview();
|
||||
|
||||
@@ -41,14 +41,12 @@
|
||||
|
||||
<form id="format-bar">
|
||||
<label for="input-prefix">파일명 포맷</label>
|
||||
<input type="text" id="input-prefix" value="photo" placeholder="접두사" />
|
||||
<span class="format-sep">_</span>
|
||||
<input type="text" id="input-prefix" value="photo_" placeholder="접두사" />
|
||||
<input type="number" id="input-digits" value="4" min="1" max="6" />
|
||||
<span class="format-sep">자리 순번</span>
|
||||
<span class="format-sep">_</span>
|
||||
<input type="text" id="input-postfix" maxlength="3" size="3" placeholder="접미사" />
|
||||
<input type="text" id="input-postfix" value="_" maxlength="3" size="3" placeholder="접미사" />
|
||||
<span class="format-arrow">→</span>
|
||||
<span id="preview-name">photo_001.jpg</span>
|
||||
<span id="preview-name">photo_0001_.jpg</span>
|
||||
<span id="sel-count"></span>
|
||||
<span id="file-count">0개 파일</span>
|
||||
</form>
|
||||
|
||||
@@ -146,11 +146,10 @@ initKeyboardShortcuts({
|
||||
|
||||
// ── 포맷 미리보기 ─────────────────────────────────
|
||||
function updatePreview() {
|
||||
const prefix = inputPrefix.value.trim() || 'photo';
|
||||
const prefix = inputPrefix.value.trim() || 'photo_';
|
||||
const digits = clampDigits(inputDigits.value);
|
||||
const postfix = inputPostfix.value.trim();
|
||||
const ext = state.files.length ? getExtension(state.files[0].name) : 'jpg';
|
||||
const suffix = postfix ? `_${postfix}` : '';
|
||||
previewName.textContent = `${prefix}_${'1'.padStart(digits, '0')}${suffix}.${ext}`;
|
||||
previewName.textContent = `${prefix}${'1'.padStart(digits, '0')}${postfix}.${ext}`;
|
||||
updateNewNameLabels();
|
||||
}
|
||||
|
||||
@@ -9,14 +9,12 @@ export function clampDigits(value, fallback = 3) {
|
||||
|
||||
export function buildSequentialName(fileName, index, { prefix, digits, postfix = '' }) {
|
||||
const ext = getExtension(fileName);
|
||||
const sequence = `${prefix}_${String(index + 1).padStart(digits, '0')}`;
|
||||
const suffix = postfix ? `_${postfix}` : '';
|
||||
return `${sequence}${suffix}.${ext}`;
|
||||
return `${prefix}${String(index + 1).padStart(digits, '0')}${postfix}.${ext}`;
|
||||
}
|
||||
|
||||
export function getNameFormat(prefixInput, digitsInput, digitsFallback = 3, postfixInput = null) {
|
||||
return {
|
||||
prefix: prefixInput.value.trim() || 'photo',
|
||||
prefix: prefixInput.value.trim() || 'photo_',
|
||||
digits: clampDigits(digitsInput.value, digitsFallback),
|
||||
postfix: postfixInput?.value.trim() || '',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user