Custom new folder name pattern in windows explorer
July 26, 2011 9:25 AM   Subscribe

In the Windows 7 explorer context menu, I'd like to add an item under 'new' that's like "New Folder" but instead creates a folder named e.g. 2011-07-26. I have no idea where I'd start; any approaches or software I should look into?
posted by the mad poster! to Computers & Internet (11 answers total) 2 users marked this as a favorite
 
See this StackOverflow question. This is the second Google result for "new folder explorer context menu plugin".
posted by kindall at 9:48 AM on July 26, 2011 [1 favorite]


shell extensions.. but be aware, they are a bugger to get right...
posted by k5.user at 9:57 AM on July 26, 2011


Response by poster: I see. that stackoverflow looks frightening but I guess I'll try setting it up.

What I also want to do eventually is to be able to right click on files in my Downloads folder and click on 'project name' send it to work\project\2011-07-26 creating the folder if it doesn't exist etc.. but I'm understanding that this is going to be a pain. It might be worthwhile if it works though cause it's always annoying for me to be making these folders and shuffling these files around into them before I open them/save them

The third thing I'd want to do is to be able to right click on a file and prefix today's date onto it

Maybe there's something that can be done via cygwin, like invoke a cygwin command from a button in explorer… but yeah this is going to be a process.
posted by the mad poster! at 10:14 AM on July 26, 2011


There's a program called Fast Explorer that lets you specify what command to run when you select something from the context menu. This can be a batch file, which can easily do the create-folder-based-on-date-and-move-selected-files-into-it thing. When I contracted at a Big Software Company, I used it to let me work with their brain-dead command-line-only version control system in Explorer.
posted by kindall at 10:53 AM on July 26, 2011


Response by poster: I'm almost set with the Stackoverflow registry entry but need some help with this:

So the original post says

"Command"="\"CMD\" /D /E:ON /c for /F \"tokens=1-9 delims=.,\\:/\" %%A IN (\"%%date%%.%%time%%\") DO for /F \"tokens=*\" %%a IN (\"%1\") do md \"%%~dpa\\%%A.%%B.%%C %%D;%%E;%%F\""

which creates

Tue 07.26.2011 13;53;27

I changed it to

"Command"="\"CMD\" /D /E:ON /c for /F \"tokens=1-9 delims=.,\\:/\" %%A IN (\"%%date%%\") DO for /F \"tokens=*\" %%a IN (\"%1\") do md \"%%~dpa\\%%C-%%A-%%B\""

which creates

2011-Tue 07-26

I need 'Tue' to go... anyone know what's going on in that 'for tokens do' string?
posted by the mad poster! at 11:05 AM on July 26, 2011


the long command there is breaking up the output of the "date" command based on the delimiters in the delims string. So, %A looks like the first token. Run 'date' in a cmd window, and ah, I see "Tue 07/26/2011"

LOOKS like you need a space as the delimiter too, since %A is parsed out as "Tue 07" (the first "/" is where it currently breaks up the string) and then use the right parsed-out variables. Unsure if you can make it look something like:

"Command"="\"CMD\" /D /E:ON /c for /F \"tokens=1-9 delims=., \\:/\" %%A IN (\"%%date%%\") DO for /F \"tokens=*\" %%a IN (\"%1\") do md \"%%~dpa\\%%D-%%B-%%C\""


(space may need to be escaped/back-slash-ified, or some other way of indicating it in the delims value)
posted by k5.user at 12:02 PM on July 26, 2011


See here for a better explanation.

The idea is that you're asking the system for the date but you have to do some work to get the answer into the format you want to use. I'm not that familiar with windows scripting to give you the answer outright, but this link should be somewhat explanatory for you.

on preview, what K5.user said, too.
posted by Pogo_Fuzzybutt at 12:07 PM on July 26, 2011


If you're not rigidly welded to the right-click workflow, the absolute easiest way to do what you want is simply to leave a few little batch files sitting in your downloads folder onto which you drag and drop things you want to do stuff to. The pathnames of items you drag and drop will be supplied to the batch script as parameters.

So to make the files you drag and drop move to %USERPROFILE%\work\project\yyyy-mm-dd you could create move-to-today.cmd and put this in it:
for /f "tokens=2-4 delims=-/ " %%A in ("%DATE%") do (
	set day=%%A
	set month=%%B
	set year=%%C
)

set destn=%USERPROFILE%\work\project\%year%-%month%-%day%
if not exist "%destn%" mkdir "%destn%"

:move-file
if not "%~1" == "" (
	move "%~1" "%destn%"
	shift
	goto move-file
)
Tweak the set statements controlled by the initial for to suit your locale's day/month/year ordering.

You could also create prefix-with-today.cmd and put this in it:
for /f "tokens=2-4 delims=-/ " %%A in ("%DATE%") do (
	set day=%%A
	set month=%%B
	set year=%%C
)

:rename-file
if not "%~1" == "" (
	rename "%~1" "%year%-%month%-%day%-%~nx1"
	shift
	goto rename-file
)
If you'd rather not litter up your downloads folder with batch scripts, save them somewhere else and put shortcuts to them on your desktop or Quick Launch bar. Windows Explorer will still launch them, with appropriate parameters, when you drag and drop files onto those shortcuts. Note that both the scripts above will accept an arbitrary number of files in a single drag/drop (that's what the shift/goto loop is for).

Even if you do end up going the registry-tweak and right-click route, I think you'll find that calling little batch files from your registry tweak instead of embedding every command necessary in the registry string itself will make you spend a lot less time in quoting hell.
posted by flabdablet at 6:03 PM on July 26, 2011


By the way, the inbuilt help on most Windows batch commands is pretty decent, though the console is a crappy interface for reading it. Try saving the following as get-help.cmd:
@set /p cmd=Get help with: 
@%cmd% /? >%cmd%.txt
@start notepad %cmd%.txt

posted by flabdablet at 6:23 PM on July 26, 2011


Response by poster: much appreciated, flabdablet, I'll try these when I have a moment and post about how I got on
posted by the mad poster! at 9:19 PM on July 27, 2011


By the way: after selecting a set of files, copy/pasting them onto a script (or shortcut to a script) does the same thing as dragging and dropping, i.e. invokes the script with the pathnames to those files as command line arguments.
posted by flabdablet at 10:31 PM on July 27, 2011


« Older How did Woodward get Stephanopoulos to speak to...   |   What recourse do I have with my useless management... Newer »
This thread is closed to new comments.