How to create bat file to publish to a web server.

Hi All,

I used to work with a guy that showed me how to set this up before, but don't remember how to do it.  Basically, he created a .bat file called Publish and somehow inserted it in the "right click" menu.  So, when I was done working on a file I could right click on the file on my development server and it would transfer the file to the production server.  It the file already existed on the production server, it would overwrite it.  Here is the code from that publish.bat file:

@if not exist "F:%~p1" mkdir "F:%~p1"
@for /f "tokens=*" %%a in ('dir %1 /b') do @copy %1 "F:%~p1\%%a"

Here is my problem... this does not work and I don't remember how to put it in the right click menu.  On my current laptop... my development server is mapped drive of Z: and my production server is a mapped drive of O:.  So, here is the order of things that I need to happen.  I am using my laptop to connect to my development project via  I would like to be able to have a windows explorer window open displaying the files on my development box.  I would like to right click on any file in that dialogue box and click on publish and a copy of that file would be put on the production server.

Any help would be great.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It would appear that the bat file presumes the current default drive and directory as the source and copies to the F: drive.  You might try changing the F: to Z:    You might also need to be more specific regarding the source file drive and directory.  As for putting the bat file on the menu try right-clik on the bat to create the applicable short cut.  Then, presuming it is not prevented, move the shortcut to the applicable menu.

Open notepad, copy the following to it, then save as c:\publish.reg
run that file, then you can delete it after it adds to the registry.  This will offer the menu item "Publish" when you right click any file and will pass that to publish.bat

Windows Registry Editor Version 5.00


@="publish.bat %1"

Hope this helps.  

You are assuming drive F:

muliganAuthor Commented:
Thanks SStory.... that did place the Publish in my right menu.  But the file transfer did not work.  My development server is mapped drive of Z: and my production server is a mapped drive of O:.  So, I need to transfer the files from z to o.
As I said earlier:

@if not exist "O:%~p1" mkdir "O:%~p1"
@for /f "tokens=*" %%a in ('dir %1 /b') do @copy %1 "O:%~p1\%%a"

or possibly

@if not exist "O:%~p1" mkdir "O:%~p1"
@for /f "tokens=*" %%a in ('dir Z:%1 /b') do @copy %1 "O:%~p1\%%a"

first line checks for existence of directory on O and creates if it does not exist

second line loops through the file names (top=using default, bottom specifically Z) and copies the files to O.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.