0

I added a "Create Date Folder" option to my context menu which calls a batch script. Basically, I right click on any background and then click on the "Create Date Folder" option and it creates a folder with the name in this format YYYYMMDD-XXX, where XXX are initials of the person creating the folder. In my case it will be LS. Everything was working fine until someone tried it on a UNC path (No letter network path) and it didn't work. I am just wondering if I can do something to my code to make it work with UNC paths.

I read about deactivating a safety register or something like that but I would like to enter code heretake a safe approach. Also, I have tried the pushd and popd commands but it creates the folder where that batch file is and I want it to create it where I do the right click.

Here is my register:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Date Folder]
@="Create Date Folder"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Date Folder\command]
@="D:\\Scripts\\getdate.bat"

Here my batch script:

@echo off
setlocal
rem get the date
rem use findstr to strip blank lines from wmic output
for /f "usebackq skip=1 tokens=1-3" %%g in (`wmic Path Win32_LocalTime Get Day^,Month^,Year ^| findstr /r /v "^$"`) do (
  set _day=00%%g
  set _month=00%%h
  set _year=%%i
  )
rem pad day and month with leading zeros
set _month=%_month:~-2%
set _day=%_day:~-2%
rem output format required is YYYYMMDD-XXX
md %_year%%_month%%_day%-LS
endlocal

I would like the date folder to be created on any UNC path where I do right click. I put a pause on my batch script and I could see the UNC path not supported message.

jeb
  • 78,592
  • 17
  • 171
  • 225
Luis
  • 3
  • 3

1 Answers1

0

I would suggest you forget about calling a at right-click time, using a command instead; in this case a one.

Here's a one line example , to set it up:

@"%__AppDir__%WindowsPowerShell\v1.0\Powershell.exe" -NoP "NI 'HKCU:\Software\Classes\Directory\Background\shell\MkStampedDir' -Va 'NOW Folder Here' -F";"NI 'HKCU:\Software\Classes\Directory\Background\shell\MkStampedDir\command' -Va '\"%__AppDir__%WindowsPowerShell\v1.0\Powershell.exe\" -NoP \"$dt=Get-Date -F {yyyyMMdd-XXX};MD \"%%V\$dt\"\"' -F"

In this case I've used the current user registry instead of the machine registry. As you did not provide any information as to how you determine the initials to use in the string I have appended XXX to represent them at this time.

After running the above , simply right-click in a directory background inside a new Explorer window and choose NOW Folder Here to create the new directory.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Hi Compo, I only got shellex in my computer in the HKCU and not shell. Would it be any problem if I run your batch-file? Also, I will enter the initials myself in each script needed. How would this code change for the HKCR if possible please? Thank you! – Luis Jul 15 '19 at 15:22
  • No, it will create the keys as necessary. Change the single instance of `XXX` in my code above to `LS` or whatever initials you're proposing. – Compo Jul 15 '19 at 15:24
  • Hi again, it works on a local drive and mapped drives but still doesn't work on UNC paths like this (\\xyz\abc\folder) :(. I wonder how the regular New folder works anywhere :P. – Luis Jul 16 '19 at 14:12
  • Hi Compo, how would I pause the batch script in powershell. I tried the pause command but it didn't pause at all. I just want to see what message I get when I try to create the folder in a UNC path. – Luis Jul 18 '19 at 14:23
  • @Luis, your above comment is not relevant to my answer, and expects that I support you as a personal assistant. Please do not do that, ask a new question, if you have one. In answer, I usually use `sleep`, which is an alias for `Start-Sleep` and accepts either `-Seconds|-S` or `-Milliseconds|-MS|-M`, e.g. `Sleep 5`, `Start-Sleep -Seconds 2.5`, `Sleep -S 7`, `Sleep -M 1200`, `Start-Sleep -Milliseconds 3700`, `Sleep -MS 6750` etc. – Compo Jul 18 '19 at 14:40
  • I am so sorry. I didn't mean to disrespect you. I just wanted to see if there is an error message on the powershell windows because it didn't create the date folder when I right click on the background of a UNC path and selected the option NOW Folder Here so that I would be able to give you more feedback. I am in Windows 10. How could I make this work on UNC paths please? – Luis Jul 19 '19 at 20:59
  • Compooo :D!!! It actually worked. For some UNC paths it doesn't but maybe I have some restrictions in there. Thank you so very much :D!!! – Luis Jul 20 '19 at 23:15
  • Hi compo, for some reason when I created a New folder anywhere and didn't change the name (Folder name stayed as New folder) and I tried to create the date folder inside that folder, I got an error in the blue powershell window and the date folder wasn't created. Would you know why that may be happening? I could live with it but I am just curious to see if that can be fixed. Thank you! – Luis Jul 22 '19 at 22:00