Create folder and move file function button

English support forum

Moderators: sheep, Hacker, Stefan2, white

jbw92
Junior Member
Junior Member
Posts: 5
Joined: 2003-12-13, 14:22 UTC

Create folder and move file function button

Post by *jbw92 »

Hi all,

Often i create a folder by pressing F7 after selecting a file (without file exension).
Thereafter i move the file into the created folder.


Can this be done by adding a button+function to the buttonbar?
If yes can you please advise how to do this?

TIA
Joop
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

1. go to menu Configuration> Cange button bar...
2. add new button
3. browse internal commands and select cm_MkDir command
4. press OK
User avatar
Stitscher
Power Member
Power Member
Posts: 1058
Joined: 2004-02-17, 12:34 UTC
Location: Hamburg, Germany

Post by *Stitscher »

2ts4242
But cm_mkdir doesn't move the slected file in the folder. ;)

Stitscher
jbw92
Junior Member
Junior Member
Posts: 5
Joined: 2003-12-13, 14:22 UTC

Post by *jbw92 »

Thanx for the reply.
What you describe is what is achieved by selecting the filename and pressing F7. No problem.
What i want is that also the selected file is moved to the created folder by pressing the same button.

TIA
Joop
User avatar
Vansumsen
Power Member
Power Member
Posts: 761
Joined: 2003-11-09, 08:16 UTC
Location: Belgique
Contact:

Post by *Vansumsen »

:arrow: jbw92

1° create those two em_command : (See the Tutorial to know how to do)

[em_dir]
cmd=%comspec% /c md
param="%T%O"

[em_copy]
cmd=%comspec% /c copy
param="%p%N" "%T%O" /b

2°Dowload and install the (tiny) tool TCMC available here >>> http://totalcmd.pl/download/add/Add/TC_Multiple_Commands

(I propose you to install this tool here : C:\Totalcmd\Tools\TCMC)

3°Create a new button :

cmd=C:\Totalcmd\Tools\TCMC\TCMC.exe 500 EMem_dir EMem_copy
Icon=Your personal choice
Comment=Create a directory with a file name and copy the file in this new dir

To use the button : Select a file into the source panel, click on the button, the directory is created in the destination panel...

Enjoy

Paul
Ouistiti, #11943

L'important n'est pas de convaincre, mais de donner à réfléchir.
The important thing is not to convince, but to incite to think.

1,77245385090552...
jbw92
Junior Member
Junior Member
Posts: 5
Joined: 2003-12-13, 14:22 UTC

Post by *jbw92 »

Thanx for the very fast reply.
Will try tomorrow.

Joop
User avatar
HolgerK
Power Member
Power Member
Posts: 5237
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Small enhancement.
This can be done with one single command:

Code: Select all

[em_mkdirAndCopyFile]
cmd=%comspec% /c 
param= md "%T%O" && copy %P%N "%T%O\" /b
Or as original asked:

Code: Select all

[em_mkdirAndMoveFile]
cmd=%comspec% /c 
param=md "%T%O" && move %P%N "%T%O\"
No need to use TCMC here.

The final button should look like this:

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /c
md "%T%O" && move %P%N "%T%O\"
%Commander_Path%\WCMICONS.DLL,63
Move file under cursor into new directory

1
-1
Thanks to Vansumsen for the idea :)

HTH,
Holger
User avatar
petermad
Power Member
Power Member
Posts: 9897
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Post by *petermad »

2HolgerK

Notice that it only works if %comspec% points to cmd.exe not if it points to command.com - hence not in Win 9x.
License #524 (1994)
Danish Total Commander Translator
TC 9.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (2004) 64bit, 'Everything' 1.4.1.992 (x64)
TC 3.11 on Android 6.0
Get:
Extended TC Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
jbw92
Junior Member
Junior Member
Posts: 5
Joined: 2003-12-13, 14:22 UTC

Post by *jbw92 »

:arrow: HolgerK

This is it (almost). Thank you very Dutch :wink:
Is it possible to perform the function in the same folder (not the opposing one)?
What is the function / which file to edit for:

Code: Select all

TOTALCMD#BAR#DATA 
%comspec% /c 
md "%T%O" && move %P%N "%T%O\" 
%Commander_Path%\WCMICONS.DLL,63 
Move file under cursor into new directory 

1 
-1
User avatar
Peter
Power Member
Power Member
Posts: 1990
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

HolgerK wrote:...
param= md "%T%O" && copy %P%N "%T%O" /b[/code]
...
Is it possible to use parts of the filename to create folders?

Example:

I have files which begins with the same letters (abc-456-ph1-inda.txt; abc-456-ph1-indb.txt; abc-456-ph2-inda.txt, ...) and want to
- "select the filename until the second "-" or (select the first 7 letters of the filename) -> result: "abc-456"
- make a folder with this name
- move all selected files to the new folder

Peter
TC 9.51 / #266191
Win 10 x64
User avatar
HolgerK
Power Member
Power Member
Posts: 5237
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

petermad wrote:2HolgerK

Notice that it only works if %comspec% points to cmd.exe not if it points to command.com - hence not in Win 9x.
You're right.

Sometime during the last century, I decided to skip this (can I say?) operation system.
OS/2 was the better environment for DOS development, Windows NT4 was the better base for windows development.
I never regretted this decision.

So for all 16Bit Dos / 32(*3/4)Windows 9x Hardliner: Vansumsen suggestion is the better way in this case. At least if the command line does not exceed the 127/255 character limit.

Kind regards,
Holger
User avatar
HolgerK
Power Member
Power Member
Posts: 5237
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

jbw92 wrote::arrow: HolgerK

This is it (almost). Thank you very Dutch :wink:
Is it possible to perform the function in the same folder (not the opposing one)?
What is the function / which file to edit for: ...
Two solutions:

A) use <Ctrl+Left> or <Ctrl+Right> to synchronize the two panels

B) replace %T with %P :

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /c
? md "%P%O" && move %P%N "%P%O"
%Commander_Path%\WCMICONS.DLL,63
Move file under cursor into new directory

1
-1
HTH,
Holger
Last edited by HolgerK on 2007-11-13, 01:16 UTC, edited 1 time in total.
User avatar
HolgerK
Power Member
Power Member
Posts: 5237
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Peter wrote:
HolgerK wrote:...
param= md "%T%O" && copy %P%N "%T%O" /b[/code]
...
Is it possible to use parts of the filename to create folders?
...
Maybe the following line will give you a hint how to do this with Batch-programming:

Code: Select all

for /F "eol=; tokens=1,2,3* delims=-." %i in ("abc-456-ph1-inda.txt") do @echo %i-%j
Replace abc-456-ph1-inda.txt with %O
and echo %i-%j with set TT="%%T%i-%j" && md %TT%
Untested!
Personal i would use a VB-script in this case. Better error handling, string operations and the FileSystemObject is easy to use in this place.
The following script could be used as base for your special wish CreateMarkedDirs.vbs

With a little knowledge in VisualBasic programming it should be no problem to adapt this small script.

HTH,
Holger
User avatar
Peter
Power Member
Power Member
Posts: 1990
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Hello

you should take a look at

http://www.totalcmd.net/plugring/Mover.html (incl. source code)

This is a function which handles with "makedir" and "moving". Maybe there is someone who can modfiy the code for all needs?

Peter
TC 9.51 / #266191
Win 10 x64
User avatar
HolgerK
Power Member
Power Member
Posts: 5237
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Sorry Peter

Actual i have less spare time to do plugin development.
Another point is, that may be Christian can add a "create directory" possibility into the MRT.
This would simplify the task of this thread to a simple file rename mask ( "[N1-5]\[N]" or [N]\[N]).
( Still hoping) :)

In the meantime you can test this litlle basic script:

Code: Select all

'Command   : MoveFiles2SubFolders.vbs
'Parameters: %L -1 1
'Tooltip   : move all marked files into subfolder with the basename of the file
' # first parameter %L Name of a list file with long file names including the complete path
' # (opt) second parameter can be use to create folders from the first N character of the filename
'       if N is less then 1, the complete filename without extension is used as new folder name
' #  (opt) third parameter (silent mode) if set to 0. all expected error messages are skipped

Const FOR_READING = 1

sFileList = WScript.arguments.Item( 0 )
nLength = -1
bSilent = false
If WScript.arguments.Count > 1 Then	nLength = WScript.arguments.Item( 1 )
If WScript.arguments.Count > 2 Then	If WScript.arguments.Item( 2 ) = 0 Then bSilent = true

Set oFSO = CreateObject( "Scripting.FileSystemObject" )

If  oFSO.FileExists(sFileList) Then

  Set oTextStream = oFSO.OpenTextFile( sFileList, FOR_READING )
  Do Until oTextStream.AtEndOfStream

	sFilePathName = oTextStream.ReadLine
	If  oFSO.FileExists( sFilePathName ) Then
	
		sPath = oFSO.GetParentFolderName( sFilePathName )
		sName = oFSO.GetBaseName( sFilePathName )
		sExtension = oFSO.GetExtensionName( sFilePathName )
		If nLength < 1 Then
			sNewPath = sPath & "\" & sName
		Else
			sNewPath = sPath & "\" & Left( sName, nLength )
		End If

		sNewFilePathName = sNewPath & "\" & sName & "." & sExtension

		If Not oFSO.FileExists( sNewPath ) Then
		
			If Not oFSO.FolderExists( sNewPath ) Then
				oFSO.CreateFolder( sNewPath )
			End If

			If Not oFSO.FileExists( sNewFilePathName ) Then
				oFSO.MoveFile  sFilePathName, sNewFilePathName 
			ElseIf not bSilent then
				WScript.Echo "Destination File exists (skipped)!: " & sNewFilePathName 
			End If
			
		ElseIf not bSilent then
			WScript.Echo "File with destination folder name exists already (skipped)!: " & sNewPath 
		End If
	End If
  Loop
  
  oTextStream.Close
  
Else

  WScript.Echo "Input file list " & sFileList & " not found."
  
End If
Save the script as "MoveFiles2SubFolders.vbs"

Create a new button:

Code: Select all

TOTALCMD#BAR#DATA
C:\Tools\totalcmd\Scripts\MoveFiles2SubFolders.vbs
%L 6
C:\Windows\System32\WScript.exe
Move fle(s) to 2 sub folder(s)
C:\Tools\totalcmd\Scripts\

-1
Compared to the above dos-commands, this script should also work correct with filenames containing german "umlaut"(s), and can handle more than one file in a single call.

Kind regards,
Holger
Post Reply