Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I had a simple batch file I would use in Windows XP to create a set of specific subfolders inside a folder. I had it set up as a Right-Click context menu so that when I right-clicked on a folder within Windows Explorer, I could execute the batch file and have the 10 specific folders created inside it.

I moved the same batch file to Windows 7. I can run the batch file manually and it works fine, however when I run it from the Right-click context menu, the folders are all created in the \Windows\System32\ directory, not in the colder that I had right-clicked upon.

I know that the "Current Directory" in Windows XP used to carry the value of the right-clicked folder, now in Windows 7 the Current Directory value seems to change to the System32 folder.

I was trying to find a way to read the current directory that the mouse right-clicked on, but cannot find that value. "CD" is the System32 folder at the start of the batch execution.

Any suggestions?

share|improve this question
    
How are you adding it to the right-click menu? –  nhinkle Apr 4 '11 at 17:31
    
Are you using relative paths or absolute paths in the script? Windows 7 changed a lot of the paths, so it may be defaulting to where the batch file executer is if it can't find the path. –  tjameson Apr 4 '11 at 17:35
    
It would help if you posted the script itself. I have a feeling that it has to do with the paths specified in the file and where the batch file is located. It also probably has a lot to do with the exact registry entries that were used to make it available in the right click context menu. In batch, %CD% will be the path that the batch file is run from. –  MaQleod Apr 4 '11 at 18:54

1 Answer 1

up vote 0 down vote accepted

You can change the command entry in the registry to add a parameter:

C:\Users\Me\Batches\make_dir.cmd "%1"

and then use that parameter in the batch file:

cd /d "%1"
md SomeDirectory
md SomeOtherDirectory

As for the confusion, I guess the working directory of the process that is started for a shell command was never really specified so it could be anything. And Windows 7 introduced libraries which probably could lead to folders residing in »non-paths«.

share|improve this answer
    
My registry entries were simply to HKCR\Directory\Shell\ where I added the Key "CreateFolders" and the command pointing to the batch file. It works, But it is only placing the folders in the System32 directory. It does not consider the "Current Directory" to be the folder that I am right-clicking on, which is what WinXP used to do. There are no paths in the script, only MD commands, so a very simple script. –  Calvin Apr 4 '11 at 19:53
    
The suggestion by Joey worked. Thanks very much. Cal –  Calvin Apr 4 '11 at 20:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.