Generate folders from selected files?!

English support forum

Moderators: white, Hacker, petermad, Stefan2

al7amimi
Junior Member
Junior Member
Posts: 5
Joined: 2017-08-26, 14:10 UTC

Generate folders from selected files?!

Post by *al7amimi »

Is there a way to select multiple files, then based on the files' names excluding extensions, we can generate folders? :?:
Registered user
TC 9.21a x64
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Generate folders from selected files?! VBScript: ForEachSelectedDo-CreateFolder.vbs

Post by *Stefan2 »

With the help of TCs' parameter and a little DOS Batch programming:

Create a button
viewtopic.php?f=3&t=50632&p=344803


as
Command : cmd /c
Parameters: FOR /F "tokens=*" %%S in ( ' TYPE "%F" ' ) Do @MD "%%~nS"
Start path:
Icon file: cmd.exe -or- WCMICONS.DLL
Tooltip:


This batch is good for names with english chars/alphabet only. For non english language read the help and try %WF or %UF (or CHCP xxx)

- - -


Better for german umlauts is to utilize a external script with VBS, PoSh or AutoHotkey.

TC Button:
Command: "D:\rive\Path to this\ForEachSelectedDo-CreateFolder.vbs"
Parameters: "%F"
Start path:
Icon file: C:\Windows\System32\WScript.exe -or- WCMICONS.DLL
Tooltip: your text Create Folder from selected Files


ForEachSelectedDo-CreateFolder.vbs

Code: Select all

'//ForEachSelectedDo-CreateFolder.vbs
'Stefan 18:47 07.10.2018 /// Found at: https://ghisler.ch/board/viewtopic.php?p=347738
Set FSO = CreateObject("Scripting.FileSystemObject")
If (Wscript.arguments.count < 1) Then MsgBox "Err, missing param '%F'" : WScript.Quit
sTCtempListPath = Wscript.arguments.Item(0)
Set oTextStream = FSO.OpenTextFile(sTCtempListPath,1)
Do Until oTextStream.AtEndOfStream
        sFullName = oTextStream.ReadLine
        If Not (Right(sFullName,1)= "\") Then Set oItem = FSO.GetFile(sFullName)
        sBase = FSO.GetBaseName(oItem)
        If Not FSO.FolderExists(sBase) Then FSO.CreateFolder sBase
Loop
oTextStream.Close
'// TC Button:
'// Command: "D:\rive\Path to this\ForEachSelectedDo-CreateFolder.vbs"
'// Parameters: "%F"
'// Start path:
'// Icon file: C:\Windows\System32\WScript.exe -or- WCMICONS.DLL
'// Tooltip: your text Create Folder from selected Files


 
polle452
Junior Member
Junior Member
Posts: 32
Joined: 2013-10-09, 20:40 UTC

Re: Generate folders from selected files?!

Post by *polle452 »

or use the 'Extended English Menus for 32bit and/or 64bit installations of TC 9.21 under Windows 10':

https://totalcmd.net/download.php?id=win10x86_amd64_eng

Petermad has these menus for several versions of TotalCommander, 32bit and 64bit Systems as well as versions for other versions of Windows.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Generate folders from selected files?!

Post by *petermad »

or use the 'Extended English Menus for 32bit and/or 64bit installations of TC 9.21 under Windows 10':
You will find the function you ask for under the menu item "Misc." -> "Make Directories in Opposite Panel with Same Name as Marked Files/Folders" or "Make Directories in Opposite Panel with Same Name + Extension as Marked Files/Folders"

See signature for Extended Menus
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Christo
Junior Member
Junior Member
Posts: 13
Joined: 2014-10-25, 11:30 UTC

Re: Generate folders from selected files?!

Post by *Christo »

petermad wrote: 2018-10-07, 20:14 UTC
or use the 'Extended English Menus for 32bit and/or 64bit installations of TC 9.21 under Windows 10':
You will find the function you ask for under the menu item "Misc." -> "Make Directories in Opposite Panel with Same Name as Marked Files/Folders" or "Make Directories in Opposite Panel with Same Name + Extension as Marked Files/Folders"

See signature for Extended Menus

Absolutely Brilliant, never will I not have enough Menu options. I can't believe I have never spotted this plugin. I love the "Make Directories in Opposite Panel with Same Name as Marked Files/Folders"

Brilliant.
User avatar
Matrix
Junior Member
Junior Member
Posts: 66
Joined: 2005-12-10, 21:15 UTC

Re: Generate folders from selected files?!

Post by *Matrix »

At the bottom of the misc. pull-down menu, it says, 'All these commends use Dos and may not work on all operating systems'

I've installed the 64bit extended menu plugin into a windows 10 64 bit machine.

I then tried to use the command to create a folder based on the files selection set. To which nothing happens.

Has this happened to others and if so how did you fix?

Your advice is apprecaited.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Generate folders from selected files?!

Post by *petermad »

2Matrix
I have Heard of one other user that has similar problems under Windows 10 - probably due to the use of

Code: Select all

echo •
to make the system make a ding sound in case of an error (unsupported drive) - this is apparently no longer supported under Windows 10, but gives no problems of executing the script at my Windows 10.
Try to replace:

Code: Select all

[em_ext_newdir]
cmd=%COMSPEC% /C
param=%Z if not exist "%P" (echo •) else if not exist "%T" (echo •) else if exist "%T%O" (echo •) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do if "%%~nn"=="" (if not exist "%T%%n" md "%T%%n") else if not exist "%T%%~nn" md "%T%%~nn"
menu=Make directories in opposite panel with same name as marked files/folders
button=wcmicons.dll,29
iconic=1
with:

Code: Select all

[em_ext_newdir]
cmd=%COMSPEC% /C
param=%Z if not exist "%P" (echo error) else if not exist "%T" (echo error) else if exist "%T%O" (echo error) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do if "%%~nn"=="" (if not exist "%T%%n" md "%T%%n") else if not exist "%T%%~nn" md "%T%%~nn"
menu=Make directories in opposite panel with same name as marked files/folders
button=wcmicons.dll,29
iconic=1
in your wcmd_win10amd64_1_eng.ini or wcmd_win10amd64_2_eng.ini file (in case you are using the 64bit version for Windows 10)
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
NotNull
Senior Member
Senior Member
Posts: 266
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Generate folders from selected files?!

Post by *NotNull »

@petermad:

Another way to write

Code: Select all

param=%Z if not exist "%P" (echo error) else if not exist "%T" (echo error) else if exist "%T%O" (echo error) else commands
would be

Code: Select all

param=%Z if exist "%P" if exist "%T" if not exist "%T%O"  ( commands ) else (echo error & pause)
(Why the if exist %T%O for multiple selected files/fodlers ? )
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: Generate folders from selected files?!

Post by *elgonzo »

2NotNull
No, your suggestion is not equivalent, and has a different behavior. Note that the else branch in your suggestion only applies to the last "if" clause. If the first or second "if" fails, it is not outputting the error message. But petermad's script outputs an error when any of the three "if" clauses fail.
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
NotNull
Senior Member
Senior Member
Posts: 266
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Generate folders from selected files?!

Post by *NotNull »

You are right (should have tested it)

But no problem :)

Code: Select all

param=%Z (if exist "%P" if exist "%T" if not exist "%T%O"  ( commands & exit /b )) & echo error & pause
or:

Code: Select all

param=%Z (if exist "%P" if exist "%T" if not exist "%T%O"  ( commands & False 2>nul )) && (echo error & pause)
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Generate folders from selected files?!

Post by *petermad »

2NotNull
I originally had different error messages for the different tests, so that is why it stayed this way.

I briefly tried your first approach, but for some reason the "commands" - did not execute - maybe because I call a second %%COMSPEC%% which I seem to have to do - otherwise the chcp 65001 doesn't take effect.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
nsp
Power Member
Power Member
Posts: 1802
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Generate folders from selected files?!

Post by *nsp »

if you do not care about Unicode (not visible in a cmd console) names, you can use TCBL.

Code: Select all

command:<path to>\tcbl.exe
parameters: %L MD $z

This will create folder with same name as file without extension in same folder.

Code: Select all

command:<path to>\tcbl.exe
parameters: -q %L MD "%T$z"
if you want to create in target folder.
User avatar
Matrix
Junior Member
Junior Member
Posts: 66
Joined: 2005-12-10, 21:15 UTC

Re: Generate folders from selected files?!

Post by *Matrix »

Thank you, everyone.

To nsp: I got your version to work but discovered it will only work on local hard drives. I.e. non-networked drives.

In fact, when I went back to the original extended menu drop-down menu, I consequently found this worked too. But again only on local drives.

Does anyone have ideas to why? Obvious answers could be virus protection, firewalls etc. But I'm hoping not.

What do you think?
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: Generate folders from selected files?!

Post by *elgonzo »

How do you access your "networked drives"?

Do you have your network shares mapped to a drive letter, and try creating folders within this mapped drive?
Or do you simply access your network shares through UNC paths?

It could perhaps be some permission restriction stipulated by the server/provider of the network share, forbidding you to create directories. But in the latter case, it could perhaps also be the software/tools in question that don't work if either current/working/source directory or the target directory is a UNC path. (For instance, cmd.exe famously does not support UNC paths for the current directory.)
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
nsp
Power Member
Power Member
Posts: 1802
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Generate folders from selected files?!

Post by *nsp »

Matrix wrote: 2020-11-24, 02:53 UTC Thank you, everyone.

To nsp: I got your version to work but discovered it will only work on local hard drives. I.e. non-networked drives.

In fact, when I went back to the original extended menu drop-down menu, I consequently found this worked too. But again only on local drives.

Does anyone have ideas to why? Obvious answers could be virus protection, firewalls etc. But I'm hoping not.

What do you think?
If you access from a mounted network drive using a letter with read/write access, all should works correctly.

The tools was not designed to work with UNC names everything you have in network neighborhood \\Server\Share\... as many console tools do not work correctly with CMD (which will process the batch). It should work anyhow if you use full names like "%T$z" or $x instead of $z as md/mkdir works with UNC names.
A good trick in batch with unc names is to use a SUBST drive instead of CD which do not work...

You can add a pause add -p or change -qp before %L to see what is going wrong... (network share not found or credentials...)
You can also edit or see the generated script adding option e. (all option must be glued after first -, like -e -ep -qep -ie ...) and try in a cmd console...
Post Reply