You are not logged in.
den4b wrote:I can add "WideCopyFile" function,
Please add it, at least un-documented / without official pronounce. For insiders only.
So we can playing around with it, and tell it only with warnings to requesters.
Done => http://www.den4b.com/forum/viewtopic.php?pid=3566#p3566 => 23. Jan. 2010
Thanks Denis.
I guess it can be use as:
procedure WideCopyFile(const FilePath, newPathAndOrName: WideString; preserve-existing-file:Boolean);
First Tests:
Basic
begin
WideCopyFile(FilePath, 'X:\Backup\ReNamerTest\' + FileName, true);
end.
Advanced for easy use
// FilePath > C:\folder\sub folder\file.ext
// FileName > file.ext
// WideExtractFilePath => C:\folder\sub folder\
// WideExtractFileDir ==> C:\folder\sub folder
// WideExtractFileDrive => C:\
// WideExtractFileName ==> file.ext
// WideExtractBaseName ==> file
// WideExtractFileExt ===> ext
var
Folders: TStringsArray;
ParentFolder, GrandParentFolder, GrandGrandParentFolder, TopMostFolder, SecondTopMostFolder,
newPathTemp, output, newPath, oldFileName, oldBaseName, oldFileExt, oldPath: WideString;
I: Integer;
Initialized: Boolean;
Procedure Initialize;
BEGIN
Initialized := True;
newPath := 'c:\temp\ReNamerTest\';
newPath := WideInputBox( 'New Path' , 'Enter path to copy files to:' , newPath);
IF Not WideDirectoryExists(newPath) Then
BEGIN
Folders := WideSplitString(newPath, '\');
for I:= 0 To Length(Folders) -1 Do
BEGIN
newPathTemp := newPathTemp + Folders[i] + '\'
//showmessage(newpathtemp)
IF Not WideDirectoryExists(newPathTemp) Then
WideCreateDir( newPathTemp )
END;
END;
END;
BEGIN
IF Not Initialized Then Initialize;
// Get parts of the current file name:
oldFileName := WideExtractFileName(FileName);
oldBaseName := WideExtractBaseName(FileName);
oldFileExt := WideExtractFileExt(FileName);
// Get parts of the current file path:
oldPath := WideExtractFileDir(FilePath);
Folders := WideSplitString(oldPath, '\');
TopMostFolder := Folders[1];
SecondTopMostFolder := Folders[2];
GrandGrandParentFolder := Folders[Length(Folders)-3];
GrandParentFolder := Folders[Length(Folders)-2];
ParentFolder := Folders[Length(Folders)-1];
// Show an MessageBox to show all possibles:
output := 'Default vars' + #13#10;
output := output + 'FilePath: ' + FilePath + #13#10;
output := output + 'FileName: ' + FileName + #13#10 + #13#10;
output := output + 'Extracted parts' + #13#10;
output := output + 'WideExtractFileDrive >>> '+ WideExtractFileDrive(FilePath) + #13#10;
output := output + 'WideExtractFileDir >>> ' + WideExtractFileDir(FilePath) + #13#10;
output := output + 'WideExtractFilePath >>> ' + WideExtractFilePath(FilePath) + #13#10;
output := output + 'WideExtractFileName >>> ' + WideExtractFileName(FilePath) + #13#10;
output := output + 'WideExtractBaseName >>> ' + WideExtractBaseName(FilePath) + #13#10;
output := output + 'WideExtractFileExt >>> ' + WideExtractFileExt(FilePath) + #13#10 + #13#10;
output := output + 'TopMost Folder >>> ' + TopMostFolder + #13#10;
output := output + 'SecondTopMost >>>> ' + SecondTopMostFolder + #13#10;
output := output + 'GrandGrandParent > ' + GrandGrandParentFolder + #13#10;
output := output + 'GrandParent >>>>>> ' + GrandParentFolder + #13#10;
output := output + 'Parent >>>>>>>>>>> ' + ParentFolder + #13#10 + #13#10;
//ShowMessage ( output );
// Building the new path or file name:
//you can use other rules before to modify the filename of the copy first.
//IF newPath have no trailing backslash, add one:
newPath := WideIncludeTrailingPathDelimiter(newPath);
//some tests of using this new copy feature:
//WideCopyFile(FilePath, newname , preserve existing file); // the syntax
//WideCopyFile(FilePath, newPath + FileName, false); // copy to new dir, same name
//ShowMessage('Debug: '+ newPath + FileName);
//WideCopyFile(FilePath, newPath + oldBaseName + '.bak', false); // copy new dir, same base, new ext
ShowMessage('Debug: '+ newPath + oldBaseName + '.bak');
//WideCopyFile(FilePath, oldPath + oldBaseName + '_bak' + oldFileExt, false); // copy in same folder as file_bak.ext
//ShowMessage('Debug: '+ oldPath + oldBaseName + '_bak' + oldFileExt);
//WideCopyFile(FilePath, oldPath + '\Backup\' + oldFileName, false); // copy in sub folder
//ShowMessage('Debug: '+ oldPath + '\Backup\' + oldFileName);
END.
Test notes:
* Boolean flag
preserve true -> "successfully renamed" - msg, but existing file will be NOT overwritten
preserve false -> "successfully renamed"- msg, existing file will be overwritten
I had expected this parameter would be meant as "overwrite True/False",
but then i saw the result was vice-versa
and though this must be meant as "preserve",
whereas i would understood this flag as meant as "overwrite Yes/No"
* there is no preview for this rule as it is an PascalScript
so i have added an MessageBox to show the result
*non-existent target-folder -> "successfully renamed" - msg, but nothing is done
Could be tested first by using "IF WideDirectoryExists(path)" (thx SafetyCar)
BTW, i had this question:
If we move an file by using:
begin
filename := 'C:\Test\nonExistentFolder\' + FileName;
end.
then the folder is created. Why not with this copy function?
So i had to create the path by myself:
var
I: Integer;
newpath, newpathtemp: WideString;
Begin
newPath := 'X:\Backup\ReNamerTest\';
IF Not WideDirectoryExists(newPath) then
begin
Folders := WideSplitString(WideExtractFileDir(newPath), '\');
for I:= 0 To Length(Folders) -1 do
begin
newpathtemp := newpathtemp + Folders[i] + '\'
//showmessage(newpathtemp)
IF Not WideDirectoryExists(newpathtemp) then
WideCreateDir( newpathtemp )
end;
end;
end.
Please beta testers: test this too and comment below before we can use this and suggest it to users.
.
.
EDIT: extent and clean-up the code
Last edited by Stefan (2010-01-30 22:56)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
I guess it can be use as:
procedure WideCopy(const oldname, newname: WideString; preserve-existing-file:Boolean);
???, I think I'm lost, WideCopy is an existing function but not to copy files
* Boolean flag
preserve true -> "successfully renamed" - msg, but existing file will be NOT overwritten
preserve false -> "successfully renamed"- msg, existing file will be overwritten
I had expected this parameter would be "overwrite", but then i saw the result was vice-versa and though this must be meant as "preserve"
I thought the same, and in my opinion the "overwrite" is more logical.
*other rules apply still to original file, so this new function can only be used as an single rule
e.g.
Rule Insert "_new"
Rule PascalScript "WideCopy()"
will not work as expected first.
Here the original file is renamed by adding "_new" and then the PascalScript doesn't finds the source anymore.
If you are saying what I understood, probably you are working with FileName, but if you use FilePath the source it's always localized unless you add modified it previously (which is not a common thing to do).
Remember: WideCopy() can only be used as function in an PascalScript when there are no other rules!
I'm still lost with this
If this software has helped you, consider getting your pro version. :)
Offline
Stefan wrote:I guess it can be use as:
procedure WideCopy(const oldname, newname: WideString; preserve-existing-file:Boolean);
???, I think I'm lost, WideCopy is an existing function but not to copy files
Upps, sorry, of course it's
procedure WideCopyFile(const oldname, newname: WideString; preserve-existing-file:Boolean);
Basic
begin WideCopyFile(FileName, 'H:\Temp\ReNamerTest\' + FileName, true); end.
I am going to modify my post above to correct this.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Stefan wrote:*other rules apply still to original file, so this new function can only be used as an single rule
e.g.
Rule Insert "_new"
Rule PascalScript "WideCopy()"
will not work as expected first.
Here the original file is renamed by adding "_new" and then the PascalScript doesn't finds the source anymore.If you are saying what I understood, probably you are working with FileName, but if you use FilePath the source it's always localized unless you add modified it previously (which is not a common thing to do).
You are right SafetyCar.
I was using "FileName" first. I have modified my example with "FilePath" now and it works.
Thank you.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Just so there is no confusion regarding the use of WideCopyFile function, here is the reference from the Wiki:
function WideCopyFile(FromFile, ToFile: WideString; FailIfExists: Boolean): Boolean;
* Rename file from FromFile to ToFile. If FailIfExists flag is TRUE, file will not be copied when destination file already exists, otherwise, destination file will be overwritten. Returns TRUE on success, otherwise FALSE.
Offline