79515377

Date: 2025-03-17 17:52:30
Score: 0.5
Natty:
Report link

I am also looking for something similar but couldn't find one that works for me. Tried @MC ND's but couldn't get it to work on a fresh install of W11 24H2 (OS Build 26100.3476); it just exits even if there was only a single line of text copied to the clipboard and also after removing:

    :: Where to create the folder should come from contextual menu as parameter
    if "%~1"=="" exit /b 1
    if not exist "%~1" exit /b

I came up with a partial solution to my own problem that may be of help to anyone looking for an answer but w/ several caveats:

  1. It is not a pure batch script. It is a batch/PowerShell hybrid.
  2. It briefly opens a window every run.
  3. It creates a temp file, which I hope to remove in the future as I slowly learn more about Powershell, and deletes it after the operation.
  4. It will create a folder per line in the clipboard.

Here's the CB2Folder.bat:

@echo off

cd /d "%~1" >nul 2>&1

setlocal enabledelayedexpansion

:: Save the clipboard content into a temporary file
for /f "delims=" %%a in ('powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"') do echo %%a >> temp_clipboard.txt

:: Loop through the file and create a folder for each line (splitted by newlines)
for /f "delims=" %%b in (temp_clipboard.txt) do (
    if not "%%b"=="" (
        echo Creating folder: %%b
        mkdir "%%b"
    )
)

:: Clean up the temporary file
del temp_clipboard.txt

To add to the context menu of a folder (will create the folders inside the selected folder) and shell (will create the folders in the current folder), move the batch script to C:\Scripts\ and save the below as a .reg file and run it.

Note: In the .reg file, the filename of the batch file CB2Folder.bat should be changed to whatever its filename is.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\RunCB2Folder]
@="Run CB2Folder in here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\RunCB2Folder\command]
@="\"C:\\Scripts\\CB2Folder.bat\""

[HKEY_CLASSES_ROOT\Directory\shell\RunCB2Folder]
@="Run CB2Folder in here"

[HKEY_CLASSES_ROOT\Directory\shell\RunCB2Folder\command]
@="\"C:\\Scripts\\CB2Folder.bat\" \"%1\""
Reasons:
  • Blacklisted phrase (2): I am also looking
  • Whitelisted phrase (-1): works for me
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: vav