Copying within same directory
Moderators: Hacker, petermad, Stefan2, white
- gromit
- Junior Member
- Posts: 25
- Joined: 2003-06-25, 03:01 UTC
- Location: Perth Western Australia
- Contact:
Copying within same directory
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
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
- gromit
- Junior Member
- Posts: 25
- Joined: 2003-06-25, 03:01 UTC
- Location: Perth Western Australia
- Contact:
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.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.
Phil
Re: Copying within same directory
Strg + c, vgromit wrote:... is there a simple way within TC where you can make a copy of a file in the same directory/folder?
- - -
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.
Hacker wrote:gromit,That would be Ctrl-C, Ctrl-V.Stefan2 wrote:Strg + c, v
Roman
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...
("Strg" is German key for English "Ctrl")
- gromit
- Junior Member
- Posts: 25
- Joined: 2003-06-25, 03:01 UTC
- Location: Perth Western Australia
- Contact:
Thanks everyone - got it now. That's pretty much what I was looking for. Awesome!Stefan2 wrote:Hacker wrote:gromit,That would be Ctrl-C, Ctrl-V.Stefan2 wrote:Strg + c, v
Roman
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...
("Strg" is German key for English "Ctrl")
Phil
PowerShell: Copy With Collision-Control
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.
you can use the following batch script to copy one file at the time.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.
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]