Create folder and move file function button
Moderators: Hacker, petermad, Stefan2, white
Create folder and move file function button
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
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

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... •
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... •
Small enhancement.
This can be done with one single command:
Or as original asked:
No need to use TCMC here.
The final button should look like this:
Thanks to Vansumsen for the idea
HTH,
Holger
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
Code: Select all
[em_mkdirAndMoveFile]
cmd=%comspec% /c
param=md "%T%O" && move %P%N "%T%O\"
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

HTH,
Holger
2HolgerK
Notice that it only works if %comspec% points to cmd.exe not if it points to command.com - hence not in Win 9x.
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 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar

This is it (almost). Thank you very Dutch

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
Is it possible to use parts of the filename to create folders?HolgerK wrote:...
param= md "%T%O" && copy %P%N "%T%O" /b[/code]
...
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 10.xx / #266191
Win 10 x64
Win 10 x64
You're right.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.
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
Two solutions:jbw92 wrote:HolgerK
This is it (almost). Thank you very Dutch![]()
Is it possible to perform the function in the same folder (not the opposing one)?
What is the function / which file to edit for: ...
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
Holger
Last edited by HolgerK on 2007-11-13, 01:16 UTC, edited 1 time in total.
Maybe the following line will give you a hint how to do this with Batch-programming:Peter wrote:Is it possible to use parts of the filename to create folders?HolgerK wrote:...
param= md "%T%O" && copy %P%N "%T%O" /b[/code]
...
...
Code: Select all
for /F "eol=; tokens=1,2,3* delims=-." %i in ("abc-456-ph1-inda.txt") do @echo %i-%j
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
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
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 10.xx / #266191
Win 10 x64
Win 10 x64
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:
Save the script as "MoveFiles2SubFolders.vbs"
Create a new button:
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
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
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
Kind regards,
Holger