You are not logged in.
Pages: 1
I need a script to synchronize filenames in different file paths i.e. drives (D:\, F:\, G:\...). To recognize which ones to rename, conditions are:
- same file size in bytes
- same extension
- or same CRC (if possible)
- skip renaming of same filenames
Those files would be added in files table and compared. If in one drive are two or more identical files give an error and/or ignore renaming. To determine direction of synchronizing filenames, create and point the line in code so user can choose direction.
Upper line in script renames/gives lower one new filenames. Could be G:\ gives D:\ new filenames...
Examples:
D:\Movies\Salt 2010\Noir.nfo 3,986
D:\Movies\Salt 2010\Salt.2010.R5.LiNE.Xvid {1337x}-Noir.avi 735,872,924
D:\Movies\Salt 2010\Salt.2010.R5.LiNE.Xvid {1337x}-Noir.srt 58,703becomes
G:\Movies\Salt 2010\1337x.Org.txt 26
G:\Movies\Salt 2010\Blazinseedboxes.com.txt 83
G:\Movies\Salt 2010\Noir.nfo 3,986 ---> (ignored)
G:\Movies\Salt 2010\Salt [2010].srt 58,703 ---> Salt.2010.R5.LiNE.Xvid {1337x}-Noir.srt 58,703
G:\Movies\Salt 2010\Salt.2010.R5.LiNE.Xvid {1337x}-Noir.avi 735,872,924 ---> (ignored)
Note: files don't have to be in same path as here!
I hope that I described everything...
TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!
Offline
This is one tricky task... Anyhow, below is a script to get you going.
The script will check for each file, extract the path without the ORIGIN to construct the target path in TARGET. Then, it will enumerate all files in the target path with the same extension as the original file and detect a file that has a different filename but the same size. A dialog is displayed to confirm the paths and when confirmed by user the matching file in TARGET is renamed to match the filename in ORIGIN.
const
ORIGIN = 'D:\Temp\CopyA\'; // can be 'C:\'
TARGET = 'D:\Temp\CopyB\'; // can be 'D:\'
var
VariablePath: WideString;
TargetPath: WideString;
TargetMask: WideString;
TargetRenamePath: WideString;
Files: TStringsArray;
I: Integer;
Prompt: WideString;
begin
// check that filename matches our origin
if WideSameText(ORIGIN, WideCopy(FilePath, 1, WideLength(ORIGIN))) then
begin
// prepare target path, target mask, and target rename path
VariablePath := WideCopy(WideExtractFilePath(FilePath),
WideLength(ORIGIN) + 1, WideLength(FilePath) - WideLength(ORIGIN));
TargetPath := TARGET + VariablePath;
TargetMask := '*' + WideExtractFileExt(FilePath);
TargetRenamePath := TargetPath + WideExtractFileName(FilePath);
// find all files in target path matching target mask
SetLength(Files, 0);
WideScanDirForFiles(TargetPath, Files, False, False, False, TargetMask);
for I := 0 to Length(Files) - 1 do
begin
// skip files with identical filename
if not WideSameText(WideExtractFileName(Files[i]), WideExtractFileName(FilePath)) then
begin
// skip files with different sizes
if WideFileSize(Files[i]) = WideFileSize(FilePath) then
begin
// found matching file, confirm and rename
Prompt := 'Found two matching files:' + #13#13 + FilePath + #13 + Files[i] +
#13#13 + '...rename matching file to?' + #13#13 + TargetRenamePath;
if WideDialogYesNo(Prompt) then
begin
// rename target file
WideRenameFile(Files[i], TargetRenamePath);
end;
// stop processing other matching files, just in case
Break;
end;
end;
end;
end;
end.
Offline
A dialog is displayed to confirm the paths and when confirmed by user the matching file in TARGET is renamed to match the filename in ORIGIN.
That was/could be the issue in case we have a lots of files. Dialog has Yes and No buttons. There is no way to cancel dialog, even cannot close ReNamer. Better solution is to see regular preview in files table, then hit Rename
Nevertheless I successfully synchronized filenames. Thank you
P.S. Cannot sort list by path and filename so I can see changes more clearly. Is it possible to do that somehow?
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.avi
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.nfo
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.srt
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.sub
D:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.avi
D:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.srt
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.avi
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.nfo
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.srt
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.sub
G:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.avi
G:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.srtto be
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.avi
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.avi
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.nfo
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.nfo
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.srt
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.srt
D:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.sub
G:\Movies\Ali [2001]\Ali[2001]DvDrip[Eng]-prithwi.sub
D:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.avi
G:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.avi
D:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.srt
G:\Movies\Alice In Wonderland\Alice.in.Wonderland.DVDRip.XviD-DiAMOND.srt
TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!
Offline
Pages: 1