MCPcopy
hub / github.com/kanasimi/work_crawler / rename

Function rename

arrangement/renamer.js:437–485  ·  view source on GitHub ↗
(fso_name, is_file)

Source from the content-addressed store, hash-verified

435 }
436
437 function rename(fso_name, is_file) {
438 var fso_key = is_file ? target_files[fso_name]
439 : target_directories[fso_name];
440 if (!fso_key) {
441 for ( var file_name in target_files) {
442 var _matched = file_name.match(/^(.+)(\.[^.]+)$/);
443 // console.log([ _matched[1], fso_name ]);
444 if (_matched && _matched[1] === fso_name) {
445 CeL.warn('在目錄改名之前就已先壓縮成了檔案? ' + file_name);
446 fso_key = target_files[fso_name = file_name];
447 break;
448 }
449 }
450 }
451
452 if (false && /Demi/.test(fso_name)) {
453 console.log([ is_file, target_files, target_directories ])
454 console.log([ fso_key, fso_name, full_title ]);
455 }
456 if (!fso_key || fso_name.includes(full_title)) {
457 return;
458 }
459 var move_to = CeL.to_file_name(full_title).replace(/\.+$/, ''),
460 //
461 from_page = (move_to + matched[2])/* .replace(/_/g, ' ') */,
462 //
463 file_name = matched[1]/* .replace(/_/g, ' ') */;
464 if (is_file && (from_page.includes(file_name)
465 // from_page 有較多資訊。
466 || from_page.toLowerCase().includes(file_name))) {
467 move_to += matched[2];
468 } else {
469 move_to += '.' + fso_name;
470 }
471 // console.log(JSON.stringify(fso_name));
472 // console.log(JSON.stringify(move_to));
473 CeL.info(fso_name + '→' + move_to);
474 var error = CeL.fs_move(target_directory + fso_name,
475 target_directory + move_to);
476 if (error) {
477 CeL.error(error);
478 } else if (is_file) {
479 delete target_files[fso_name];
480 fso_name = move_to;
481 } else {
482 delete target_directories[fso_name];
483 fso_name = move_to;
484 }
485 }
486
487 CeL.debug(matched[0] + ': ' + full_title, 3, 'rename_process');
488 rename(matched[0], true);

Callers 1

rename_processFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected