topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • November 20, 2018, 09:55 PM
  • Proudly celebrating 13 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Create Folder, Give It Name: Current Date and Time  (Read 1033 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
DONE: Create Folder, Give It Name: Current Date and Time
« on: October 17, 2018, 08:56 PM »
Searching the Internet I came across the following PowerShell script:

New Folder Date Time.ps1

$folderName = (Get-Date).tostring("yyyy-MM-dd hh-mm-ss")
New-Item -itemType Directory -Path . -Name $FolderName
Executin

IF this .ps1 file is in the current directory, and executed by PowerShell, an example of the result will be a new folder:

2018-10-17 07-28-52

Here is the challenge, however....

Create in the current folder (subdirectory) the above new folder, current date and time.  From the context menu.  And don't require that the executable script reside in the current folder -- executable script (or program??) should be in some other permanent location.

Seems odd that such does not already exist out there somewhere.

All thoughts, suggestions appreciated!

Nicholas Kormanik


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #1 on: October 17, 2018, 10:06 PM »
Double-click on the Create Date-Time Folder - Install.reg file and answer Yes to let it merge with the registry.

It'll create a menu item called Create Date-Time Folder in the context menu of folders only, ie. you need to right-click on a folder to use it.

Create Date-Time Folder - Install.reg
Code: Text [Select]
  1. Windows Registry Editor Version 5.00
  2.  
  3. [HKEY_CLASSES_ROOT\Folder\shell\Create Date-Time Folder\command]
  4. @="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -sta -ExecutionPolicy Bypass -NoProfile -Command \"New-Item -ItemType Directory -Path '%1' -Name ((Get-Date).tostring('yyyy-MM-dd hh-mm-ss'))\""

If you don't want the output window that opens you can add | Out-Null after the two close brackets, ie. )) | Out-Null \""


And to remove it, double-click on the other file and answer Yes to merge it.

Create Date-Time Folder - Remove.reg
Code: Text [Select]
  1. Windows Registry Editor Version 5.00
  2.  
  3. [-HKEY_CLASSES_ROOT\Folder\shell\Create Date-Time Folder]


ADDENDUM: Added two more .reg files, these are to Install/Remove the context menu item for when you right-click on the background from within a folder, (ie. you don't need to right-click on a folder).

Windows Registry Editor Version 5.00

Code: Text [Select]
  1. [HKEY_CLASSES_ROOT\Directory\Background\shell\Create Date-Time Folder\command]
  2. @="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -sta -ExecutionPolicy Bypass -NoProfile -Command \"New-Item -ItemType Directory -Path '%1' -Name ((Get-Date).tostring('yyyy-MM-dd hh-mm-ss'))\""

Code: Text [Select]
  1. Windows Registry Editor Version 5.00
  2.  
  3. [-HKEY_CLASSES_ROOT\Directory\Background\shell\Create Date-Time Folder]

2018-10-18 14_51_06-K__.pngDONE: Create Folder, Give It Name: Current Date and Time
« Last Edit: October 18, 2018, 01:52 AM by 4wd, Reason: Got my Out-Null position wrong :/ »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 327
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #2 on: October 18, 2018, 01:10 AM »
@4wd cool job!
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #3 on: October 18, 2018, 01:50 AM »
It actually doesn't need the following parameters -sta -ExecutionPolicy Bypass -NoProfile but it won't do any harm to leave them.

I was just being lazy and didn't remove them when I modified another file  :)
« Last Edit: October 18, 2018, 04:09 AM by 4wd »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #4 on: October 18, 2018, 04:55 AM »
4wd, ya did it again.  Exactly what I was hoping for.

Perhaps other Windows users will find their way here, and download some great little tools to make life a little easier.

Thanks!

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #5 on: October 24, 2018, 01:50 AM »
Curious if anyone else gets the following error when the 'background' reg is used, and attempting to create date-time folder:

"explorer.exe

This file does not have an app associated with it for performing this action. 
(...etc)."


I've been trying to research it, but seem to arrive at dead ends.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #6 on: October 24, 2018, 04:01 AM »
More info, Desktop background or the background of a folder in File Explorer?

The image in my original post shows what I mean for the second.

Fwiw, I get that using the context menu for MediaInfo, sometimes it does it, most of the time it works.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #7 on: October 24, 2018, 04:45 AM »
Both Desktop background and background of a folder.  Both give that damn error message.

Spent hours trying to see what others have done out there.  Tried many suggestions.  No use.

The really weird thing is, I think I remember encountering this issue before, maybe a year or so ago.  Should have documented the solution then, and saved such in a retrievable place.


nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #8 on: October 24, 2018, 04:48 AM »
I'm wondering what explorer.exe has to do with it anyway.  It's PowerShell we're using....

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 9,820
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #9 on: October 24, 2018, 02:36 PM »
I'm wondering what explorer.exe has to do with it anyway.  It's PowerShell we're using....


That could be because explorer.exe isn't just Window explorer.  It's the shell.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #10 on: October 24, 2018, 06:00 PM »
If one puts the entire error message into a Google search, gets a ton of hits.

But no one seems to have a definitive answer.

I'm in the perplexing situation now where I've implemented a bunch of the suggestions out there -- none worked -- and now I'm wondering if I should regress to a backup I made just prior to the said implementations.

Go figure.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #11 on: October 24, 2018, 07:34 PM »
I found it just stopped doing it for some reason, whether it was an update or something I installed who knows.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,258
  • Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #12 on: October 24, 2018, 09:14 PM »
@4wd:
I found it just stopped doing it for some reason, whether it was an update or something I installed who knows.
Ruddy heck. I'd speculate that the cause was likely to be the Registry settings had been zapped (changed/deleted) by a Windows update.
Pity. That was a nifty fix too.    :Thmbsup:
What to do? Presumably reinstall as at 4wd Reply #1 on: 2018-10-17, 22:06:42 ยป?

You'd never know if/when it had been zapped again though. Might need to do that reinstall each time prior to running the thing (or as a default part of running it) every time, just in case. Belts-and-braces.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #13 on: October 25, 2018, 01:35 AM »
Regarding the original question above, I discovered (i.e., Google search) that 4wd's PowerShell script also works by calling from a batch file.

Place the two below together into the same fixed folder:

New Folder Date Time.bat:

@ECHO OFF
PowerShell.exe -Command "& '%~dpn0.ps1'"


New Folder Date Time.ps1:

$folderName = (Get-Date).tostring("yyyy-MM-dd hh-mm-ss")
New-Item -itemType Directory -Path "C:\0_SAS_1" -Name $FolderName


In the registry "command" space place the "path+New Folder Date Time.bat":

[HKEY_CLASSES_ROOT\Directory\Background\shell\Create Date-Time Folder\command]
@="\"C:\\Windows System Tools\\0 Create Date-Time Folder\\New Folder Date Time.bat\""


From handy context menu in folder background.  Easy peasy.  And no rude error message.

The only remaining fly-in-the-ointment is the specific location where the new date-time folder is created.  In the case above, it's bolded: C:\0_SAS_1.  Only works with respect to that one folder location.  Would greatly prefer that it work in ANY folder background, and create the new date-time folder in that folder.

But, at least....





nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 364
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #14 on: October 25, 2018, 01:51 AM »
By the way, I ended up regressing to back-up.  All the "fixing" screwed the pooch.  Clear anomalies.  As said, no definitive answers.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #15 on: October 25, 2018, 04:34 PM »
You need to pass through the parameter given to the batch file when it's called.

On my phone atm but the batch receives the current folder in parameter %1, you need to pass it through to PowerShell.

At the start of the PoSh script you need:

Param (
  [string]$folder
)

$folder now contains the current path so you can put it after the -Path parameter in the New-Item cmdlet.

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,419
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #16 on: October 25, 2018, 05:56 PM »
64 bit, Windows 10, PC:

"This file does not have an app associated with it for performing this action. (...etc)."
-Error Message

#metoo


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,016
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #17 on: October 25, 2018, 07:09 PM »
64 bit, Windows 10, PC:

"This file does not have an app associated with it for performing this action. (...etc)."
-Error Message

#metoo



Windows 10 is the problem, it happens across different configurations, different programs.

nogojoe

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 160
    • View Profile
    • Donate to Member
Re: DONE: Create Folder, Give It Name: Current Date and Time
« Reply #18 on: October 26, 2018, 04:59 AM »
Curious if anyone else gets the following error when the 'background' reg is used, and attempting to create date-time folder:

"explorer.exe

This file does not have an app associated with it for performing this action. 
(...etc)."


I've been trying to research it, but seem to arrive at dead ends.


getting the same message Win XP 3
Often the most convincing people are those who have lost the plot so much they don't recognize the difference between fact and fantasy