Copying within same directory

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
gromit
Junior Member
Junior Member
Posts: 25
Joined: 2003-06-25, 03:01 UTC
Location: Perth Western Australia
Contact:

Copying within same directory

Post by *gromit »

Sorry if this is a FAQ, but is there a simple way within TC where you can make a copy of a file in the same directory/folder?

The sort of behaviour I'm looking for is how Windows Explorer allows you to make a copy in the same directory by right click and drag.

TIA
Phil
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Post by *sidefx88 »

A file cannot be copied in the same directory/folder. One file can have the same name inside a folder.

I usually copy a file in the same location but renaming it at the same time. To do this, I press Shift + F5 in Total Commander.
I Love Total Commander!
User avatar
gromit
Junior Member
Junior Member
Posts: 25
Joined: 2003-06-25, 03:01 UTC
Location: Perth Western Australia
Contact:

Post by *gromit »

sidefx88 wrote:A file cannot be copied in the same directory/folder. One file can have the same name inside a folder.

I usually copy a file in the same location but renaming it at the same time. To do this, I press Shift + F5 in Total Commander.
Thanks for that sidefx88. I think the Shift+F5 suggestion is the best route for me at this stage. I suppose it's because I am stuck with Windows Explorer at work that I am used to doing things this way.
Phil
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Copying within same directory

Post by *Stefan2 »

gromit wrote:... is there a simple way within TC where you can make a copy of a file in the same directory/folder?
Strg + c, v



- - -


You can also create your own command by utilizing TCs variables and DOS or PowerShell commands like

[face=timesnewroman]Comm: cmd /c
Param: COPY %P%N "%P%O_copy.%E"[/face]


To prevent overwriting existent files, you would need a external batch file with more error handling.
(A simple one would be: [face=timesnewroman]if not exists "%P%O_copy.%E" COPY %P%N "%P%O_copy.%E"[/face])


You can use this as a button, or in usercmd.ini and then add an keyboard shortcut to it.



 
User avatar
gromit
Junior Member
Junior Member
Posts: 25
Joined: 2003-06-25, 03:01 UTC
Location: Perth Western Australia
Contact:

Post by *gromit »

Thanks Stefan - I'll give that a go :)
Phil
User avatar
Hacker
Moderator
Moderator
Posts: 13073
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

gromit,
Stefan2 wrote:Strg + c, v
That would be Ctrl-C, Ctrl-V. ;)

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Hacker wrote:gromit,
Stefan2 wrote:Strg + c, v
That would be Ctrl-C, Ctrl-V. ;)

Roman
:D

Since we can hold down the Ctrl key, and just press C and then V, I tried to visualize that with "Strg + c, v".

Ahh, and then I am german/english tricked again,... firstly I had wrote Ctrl, but changed it to Strg afterwards... :oops: :wink:


("Strg" is German key for English "Ctrl")

 
User avatar
gromit
Junior Member
Junior Member
Posts: 25
Joined: 2003-06-25, 03:01 UTC
Location: Perth Western Australia
Contact:

Post by *gromit »

Stefan2 wrote:
Hacker wrote:gromit,
Stefan2 wrote:Strg + c, v
That would be Ctrl-C, Ctrl-V. ;)

Roman
:D

Since we can hold down the Ctrl key, and just press C and then V, I tried to visualize that with "Strg + c, v".

Ahh, and then I am german/english tricked again,... firstly I had wrote Ctrl, but changed it to Strg afterwards... :oops: :wink:

("Strg" is German key for English "Ctrl")

 
Thanks everyone - got it now. That's pretty much what I was looking for. Awesome!
Phil
User avatar
makinero
Senior Member
Senior Member
Posts: 268
Joined: 2013-10-26, 10:05 UTC

Post by *makinero »

How to auto renaming when copying all similar filenames (without continuous confirmation)

123.wav (100 MB)
123.wav (200 MB) another file

I like rename:

123.wav
123(2).wav
123(3).wav
123(4).wav
etc.
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Copy With Collision-Control

Post by *Stefan2 »

 
Proof of concept

Copy With Collision-Control:

FROM:
Test File1.ext
Test2.ext

TO:
Test File1.ext
Test File1(2).ext
Test File1(3).ext
...
Test2.ext
Test2(2).ext
Test2(3).ext
...



USE e.g.:

PowerShell script for use with TotalCommander

Command: PowerShell
Parameter: <one script line from below>
Icon: PowerShell


For one selected file:
[face=timesnewroman]$B ="""%P%O""";$E=""".%E""";$C=2;$N="""$B($C)$E""";while (Test-Path $N){$C++; $N="""$B($C)$E"""};copy """%P%N""" """$N"""[/face]

For one OR all selected files:
[face=timesnewroman]TYPE %F | %%{$_ -match """(.+)\.(.+)""";$B=$matches[1];$E=$matches[2];$C=2;$N="""$B($C)$E""";while(Test-Path $N){$C++;$N="""$B($C)$E"""};copy """%P%N""" """$N"""}[/face]



Don't trust me. Test it first, and report back if it works.
This script fails for example if there is no dot and no extension found, e.g. on folders.
To works there too, we have to write more code, e.g.
TYPE %F | %%{if($_ -match """\."""){ ... } else {...}
and so on...

--------------------

EDIT:
For one OR all selected files (with or without extension) or folders:


[face=timesnewroman]TYPE %L|%%{$C=2;$O=$_;if(Test-Path $O){if((dir $O).PsIsContainer -or ($O -notmatch """\.""")){$O=$O -replace """\\$""";$N="""$O($C)""";while(Test-Path $N){$C++;$N="""$O($C)"""}}else{$O -match """(.+)\.(.+)""";$B=$matches[1];$E=$matches[2];$N="""$B($C)$E""";while(Test-Path $N){$C++;$N="""$B($C)$E"""}}};copy """$O""" """$N"""}[/face]

(yes, that is one long line here)


Explanation:
% is doubled and quotes are tribled due to TCs' parsing.
%L >>> TCs' parameter
$O >>> PoSh variable: origin name
$C >>> PoSh variable: counter
$B >>> PoSh variable: basename
$E >>> PoSh variable: extension
$N >>> PoSh variable: new name

Line formated version:

Code: Select all

TYPE %L | 
ForEach-Object{
	$Counter=2;$OriginName=$_;
	#If file from list really exists:
	if(Test-Path $OriginName){
	#IF folder or basename-only file:
	if((dir $OriginName).PsIsContainer -or ($OriginName -notmatch """\.""")){
		#Remove TCs' trailing backslash:
		$OriginName=$OriginName -replace """\\$""";
		#Compose new name:
		$NewName="""$OriginName($Counter)""";
		#If this name already exists, increase counter and test again:
		while(Test-Path $NewName){$Counter++;$NewName="""$OriginName($Counter)"""}
	}else{
		#Split line from filelist at last dot:
		$OriginName -match """(.+)\.(.+)""";
		$BaseName=$matches[1];
		$Extension=$matches[2];
		$NewName="""$BaseName($Counter)$Extension""";
		while(Test-Path $NewName){$Counter++;$NewName="""$BaseName($Counter)$Extension"""}
	}
};
#Do the job and create a copy with trailing counter:
copy """$OriginName""" """$NewName"""
}


 
Last edited by Stefan2 on 2014-09-22, 14:04 UTC, edited 1 time in total.
User avatar
nsp
Power Member
Power Member
Posts: 1816
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Post by *nsp »

makinero wrote:How to auto renaming when copying all similar filenames (without continuous confirmation)

123.wav (100 MB)
123.wav (200 MB) another file

I like rename:

123.wav
123(2).wav
123(3).wav
123(4).wav
etc.
you can use the following batch script to copy one file at the time.

Code: Select all

@echo off

SET "fileName=%2%~n1%~x1"
goto:doCopy

:loop
SET /a fileCounter+=1
SET "fileName=%2%~n1(%filecounter%)%~x1"
:doCopy
IF EXIST "%fileName%" GOTO:loop
copy "%1" "%filename%"
ENDLOCAL
goto:eof
[quote][/quote]
Post Reply