#1 2008-01-20 15:43

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Make a COPY instead of renaming or moving

Hi Denis, hi all,

i think there was an other thread (or post) about this topic but i didn't found it.

Denis, can you add an COPY rule?

Some times we want to COPY our files instead of renaming and/or moving the originals.

Maybe an new rule or option like "[ ] Make a COPY instead of MOVING / RENAMING"


Just an idea, what do you thing?


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

#2 2008-01-21 00:14

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,376

Re: Make a COPY instead of renaming or moving

To tell you the truth, I have a special boolean flag inside ReNamer:

MyRenameCopyFiles: Boolean = False; // WARNING: Copy mode for renaming!!

It is just a matter of switching this flag to the TRUE state. BUT, I did not let user to choose just yet, because I'm just not ready to take responsibility of copying the files. This can introduce several problems. First, copying process will take much more time than the renaming process does, and because ReNamer is a single threaded application - there is no way to stop/cancel the operation OR to track the progress.

Few other people asked me that question in the past (over the email I think), so I had to tell them this: You can simulate this feature by creating a temporary copy of your files (manually), and then rename them as you would normally do.

Offline

#3 2010-01-06 13:18

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make a COPY instead of renaming or moving

begin
  FileWriteContent(WideExtractFilePath(FilePath)  + '(copy) ' + FileName, FileReadContent(FilePath));
end.

this wouldn't help??? hmm

There is just the known problem that, because of been a script it's executed on the preview.

Maybe the pascal could include a var to know that we are renaming or previewing

something like

begin
  If WeAreRenaming then
    FileWriteContent(WideExtractFilePath(FilePath)  + '(copy) ' + FileName, FileReadContent(FilePath));
end.

--- EDITING ---

Nah, probably this last script would not work in the way I was thinking to keep the original name on the original file should be necesary to add after:
FileName:= WideExtractFileName(FilePath);


But Is very dangerous because
1. (now) it doesn't check if the destination file already exists
2. All the file is loaded into the memory and the computer will suffer a lot with large files

roll  sad


Any way I don't need this script, but I think a var like that could be very useful in other cases too...

Last edited by SafetyCar (2010-01-06 13:46)


If this software has helped you, consider getting your pro version. :)

Offline

#4 2010-01-06 13:50

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make a COPY instead of renaming or moving

Oh, sorry, the scripts are only executed on the preview not in the renaming...................... I forgot that

Last edited by SafetyCar (2010-01-06 13:50)


If this software has helped you, consider getting your pro version. :)

Offline

#5 2010-01-06 13:52

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,376

Re: Make a COPY instead of renaming or moving

You are forgetting that rules are used ONLY during Preview to generate new names. Rename operation simply renames files according to the table. Hence, WeAreRenaming flag is not possible logically.

You can still simulate this in PascalScript by marking the rule only for final Preview. I can add "WideCopyFile" function, but this will still not solve the problem with possible conflicting paths.

EDITED: Just saw your previous post! wink

Last edited by den4b (2010-01-06 13:53)

Offline

#6 2010-01-06 14:07

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make a COPY instead of renaming or moving

OK, I don't know, I leave the "WideCopyFile" discussion to those who asked for copying...

I just don't need it  roll . I was trying to help (Not with very good luck hmm  tongue )

Last edited by SafetyCar (2010-01-06 14:08)


If this software has helped you, consider getting your pro version. :)

Offline

#7 2010-01-14 13:20

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Make a COPY instead of renaming or moving

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.

den4b wrote:

but this will still not solve the problem with possible conflicting paths.

Can't you re-use your function from the main renaming feature for this issue?
Can't you provide an parameter for the "WideCopyFile" function, like "WideCopyFile(oldName, NewName, force_on_conflicts)"


Just questions, no push!
An simple  "WideCopyFile(oldName,   FilePath + '\subFolder\NewName' + oldExt)" would be enough too.

Maybe Windows will anyway not allow to overwrite existing files.


Thanks for your offer.


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

#8 2010-01-14 15:56

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make a COPY instead of renaming or moving

Some time ago I did this to serialize a file if there is already other file in the drive with the same name.

Probably can be adapted to this problem

var
  NewFileName: WideString;
  Counter: Integer;

function needs_serialize(const S: WideString): Boolean;
begin
  Result := True;
  If Result then If FilePath=S then Result := False else Result := True;
  If Result then If WideFileExists(S) or WideDirectoryExists(S) then Result := True else Result := False;
end;

begin
  NewFilePath := WideExtractFilePath(FilePath) + FileName;

  Counter := 2;
  While needs_serialize(NewFilePath) do
    begin
      NewFilePath := WideCopy(FileName, 1, Length(FileName)-Length(WideExtractFileExt(FileName))) + ' (' + IntToStr(Counter)+ ')' + WideExtractFileExt(FileName);
      Counter := Counter + 1;
    end;

  FileName := NewFilePath;
end.

So... by  checking if the new path already exist you can avoid the conflict

- - - - -
Oh, the files on renamer list should be taken in account too.

Last edited by SafetyCar (2010-01-14 16:02)


If this software has helped you, consider getting your pro version. :)

Offline

#9 2010-01-14 16:14

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Make a COPY instead of renaming or moving

SafetyCar wrote:

Some time ago I did this to serialize a file if there is already other file in the drive with the same name.

Probably can be adapted to this problem

var
  NewFileName: WideString;
  Counter: Integer;

function needs_serialize(const S: WideString): Boolean;
begin
  Result := True;
  If Result then If FilePath=S then Result := False else Result := True;
  If Result then If WideFileExists(S) or WideDirectoryExists(S) then Result := True else Result := False;
end;

begin
  NewFilePath := WideExtractFilePath(FilePath) + FileName;

  Counter := 2;
  While needs_serialize(NewFilePath) do
    begin
      NewFilePath := WideCopy(FileName, 1, Length(FileName)-Length(WideExtractFileExt(FileName))) + ' (' + IntToStr(Counter)+ ')' + WideExtractFileExt(FileName);
      Counter := Counter + 1;
    end;

  FileName := NewFilePath;
end.

>> If WideFileExists(S) or WideDirectoryExists(S)

That's already there?  big_smile
I didn't have searched good enough  roll 

Then "WideCopyFile" could be used with more security.

Great find!  tongue


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

#10 2010-01-14 16:19

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make a COPY instead of renaming or moving

Yes that's it, and the previous line is because we only need to serialize if the file is different (not itself).

- - - - -
Mmmm in this case, as we are copying, could have sense to rename if the target is the same as the origin  neutral

Last edited by SafetyCar (2010-01-14 16:21)


If this software has helped you, consider getting your pro version. :)

Offline

Board footer

Powered by FluxBB