Create Folder with today's Date & file name under cursor

English support forum

Moderators: white, Hacker, petermad, Stefan2

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

Create Folder with today's Date & file name under cursor

Post by *Matrix »

I can create a folder with today's date as follows:

Command:
cmd /c md "%date%"

I've recently discovered total commander extended menu options:

https://totalcmd.net/plugring/win10amd64_eng.html

Within is a command which creates a folder in the opposite panel, with the name of the folder/file under the cursor. Brilliant!

Description:
Make directories in opposite panel with same name as marked files/folders

Command:
%COMSPEC% /C

Parameters:
%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"

I would like to combine the two where today's date prefixes the name of the folder/file under the cursor and been struggling.

Can anyone provide some hints or answers?

Do you think possible?
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Re: Create Folder with today's Date & file name under cursor

Post by *gdpr deleted 6 »

Note that all of the following suggestions are unverified and untested. So, don't take my post as a concrete and accurate answer, but rather as a collection of some hints and pointers...


The only piece you need to focus on in the parameter script is the actual md command, as this must have the folder name as its argument. So, to alter the name of folder to be created, you would need to alter this argument in some way. Currently it is specified as:

Code: Select all

md "%T%%~nn"
%T is a variable provided by TC, specifying a directory (from TC's Help: "%T inserts the current target path.")
%%~nn is the variable %%n defined in the script with the ~n modifier. %%n contains some file name, and %%~nn provides the name without extension from this file name in %%n (~n and other modifiers are explained in the cmd help for the for command. Open a cmd.exe and type "for /?", at the end of the help text you'll find the explanation about these modifiers)

So, if you want to prefix the name of the folder to be crated, slip in the prefix between %T and %%~nn, like for example:

Code: Select all

md "%Tfoobar_%%~nn"

If you want to use %DATE% instead, you could do like (replace the underscore with a space or hyphen if you want; i just used an underscore here for readability/visibility reasons):

Code: Select all

md "%T%DATE%_%%~nn"
but note that this approach is very, very brittle and can break easily. Depending on the regional settings of the machine this script is running on, dates provided by %DATE% might be formatted differently. They might be formatted as dd.mm.yyyy, which does not pose a problem. Or, they might be formatted like dd/mm/yyyy, if for instance the computer in question belongs to a Brit. And those slashes in the date will break the md command. Avoiding "illegal"/unwanted characters in %DATE% strings within the confines of Windows' batch script language can unfortunately be quite clumsy, see details here: https://stackoverflow.com/questions/864718/how-to-append-a-date-in-batch-files
User avatar
HolgerK
Power Member
Power Member
Posts: 5406
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Re: Create Folder with today's Date & file name under cursor

Post by *HolgerK »

<F7> (opposite panel : <Shift+F7>)

Code: Select all

<[Y]-[M]-[D] [N].[E]
or ( without extension):

Code: Select all

<[Y]-[M]-[D] [N]
Regards
Holger
Make our planet great again
User avatar
Matrix
Junior Member
Junior Member
Posts: 66
Joined: 2005-12-10, 21:15 UTC

Re: Create Folder with today's Date & file name under cursor

Post by *Matrix »

If you want to use %DATE% instead, you could do like (replace the underscore with a space or hyphen if you want; i just used an underscore here for readability/visibility reasons):

Code: Select all

md "%T%DATE%_%%~nn"
but note that this approach is very, very brittle and can break easily. Depending on the regional settings of the machine this script is running on, dates provided by %DATE% might be formatted differently. They might be formatted as dd.mm.yyyy, which does not pose a problem. Or, they might be formatted like dd/mm/yyyy, if for instance the computer in question belongs to a Brit. And those slashes in the date will break the md command. Avoiding "illegal"/unwanted characters in %DATE% strings within the confines of Windows' batch script language can unfortunately be quite clumsy, see details here: https://stackoverflow.com/questions/864718/how-to-append-a-date-in-batch-files
Yes, I did think along these lines as well.

Your foobar example works perfectly. However, when I insert the %date% it creates a folder:

210207~nn


This is the code I used:
%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%%date% %%~nn"

I've been using the auto-create date function for years. I have a number of set suffixes that I use for filing certain things.

I've changed my computer settings to the American format - 210207. It took a while to get used to but now all the folders align in chronologically order.

Any further thoughts? It has been very useful. Thank you.
User avatar
Stefan2
Power Member
Power Member
Posts: 4158
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Create Folder with today's Date & file name under cursor

Post by *Stefan2 »

Matrix wrote: 2021-02-07, 07:55 UTC
Description:
Make directories in opposite panel with same name as marked files/folders
HolgerK wrote: 2021-02-07, 09:03 UTC <F7> (opposite panel : <Shift+F7>)
OR, for an everlasting button (or UserDefinedCommand with possible keyboard shortcut) instead of an one-time <F7>



For ONE marked file/folder:

TC-Help: Dialog box: Configuration - Change button bar
%N places the filename under the cursor into the command line.
%O places the current filename without extension into the command line.
%E places the current extension (without leading period) into the command line.
%T inserts the current target path. Especially useful for packers.

Code: Select all

TOTALCMD#BAR#DATA
PowerShell 
MD ('%T\'+(get-date -format 'yyyy-MM-dd_HHmm')+'_%O')
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe
Test|PowerShell  Create folder in TARGET "yyyy-MM-dd_HHmm_BaseName"


-1
(Copy&Paste button code)


- - -

Example

You have:
...Left Panel ...| ... Right Panel ..........
TOTALCMD.CHM|

Select "TOTALCMD.CHM" and
execute the command, you will get:
...Left Panel ...| ... Right Panel ..........
TOTALCMD.CHM|2021-02-07_1157_TOTALCMD\



- - -


For one-or-MORE marked files/folders we would need TCs file-list and a loop like:
GC '%WF'|ForEach{ MD %T..... (GI $_).BaseName } . . . or smtg like that

TC-Help: Dialog box: Configuration - Change button bar
%L, %l, %F, %f, %D, %d, %WL, %WF, %UL, %UF
create a list file in the TEMP directory with the names of the selected files and directories,



- - -

PowerShell command aliases:
MD = New-Item -ItemType Directory -Path
GC = Get-Content
GI = Get-Item
ForEach or % = ForEach-Object 
time variables
d Day of month 1-31
dd Day of month 01-31
ddd Day of month as abbreviated weekday name
dddd Weekday name
h Hour from 1-12
H Hour from 1-24
hh Hour from 01-12
HH Hour from 01-24
m Minute from 0-59
mm Minute from 00-59
M Month from 1-12
MM Month from 01-12
MMM Abbreviated Month Name
MMMM Month name
s Seconds from 1-60
ss Seconds from 01-60
t A or P (for AM or PM)
tt AM or PM
yy Year as 2-digit
yyyy Year as 4-digit
z Timezone as one digit
zz Timezone as 2-digit
zzz Timezone
User avatar
Matrix
Junior Member
Junior Member
Posts: 66
Joined: 2005-12-10, 21:15 UTC

Re: Create Folder with today's Date & file name under cursor

Post by *Matrix »

Stefan2, that is perfect mate!!! Wow, powerful and simple. And it worked the first time.

I do not take this for granted. Thank you so much.

Kind regards,
M
Post Reply