Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been trying to setup a batch script that can be run from the context menu inside a folder. The purpose of the batch script is to populate the folder with a predetermined folder structure.

This will need to be replicated on multiple computers(Windows 7-10), so my idea was to have a network share with two batch files and one .reg file. One of the batch files labeled "install.cmd" would copy the other batch file labeled "Subfolders.cmd" to a folder on the C drive, and run the .reg file to install a shortcut on the context menu to the "Subfolders.cmd" batch file.

I have created the "Subfolders.cmd" batch file and it works, but it has to be run from inside the folder I want the folder structure setup in. I would appreciate any help on how to create the "install.cmd" batch script that would create a folder on the C drive, copy the "Subfolders.cmd" script into it, and run the .reg file to create the item in the context menu that would allow the "Subfolders.cmd" batch script to be run in selected folder.

I'd appreciate any examples and/or suggestions of more efficient ways of doing this. Thanks!

Update: As requested, I have posted the code that generates the subfolders inside an opened folder. It's pretty simple.

md "Folder1" "Folder1/Sub1A" "Folder1/Sub1B" "Folder2" "Folder2/Sub2A" "Folder2/Sub2B"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
324 views
Welcome To Ask or Share your Answers For Others

1 Answer

There is no need for all this copying.

"\computernamesharenamefolderfile.bat"

Will run a batch file stored on another computer.

Ditto the reg command

regedit /s "\computernamesharenamefolderfile.reg"

You can do the above with the older mapped drives as well as UNC.

You need to show your second script so we can see why it NEEDS to be in the folder.

EDIT

You need to specify full paths.

To get the starting folder use %V in the registry command. So (and lets get rid of the reg file) (add your bat instead of echo)

reg add "HKCRDirectoryBackgroundShellTest Commandcommand" /ve /t REG_EXPAND_SZ /d "cmd /k echo ""%V"""

In your batch use %1 to get the starting folder, and tilde (%~1) to remove quotes (see call /? for documentation). (remember create folders from the lowest level as higer levels get made automatically).

md "%~1folder1folder2"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...