[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-12
Medium Priority
Last Modified: 2008-01-09
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 VS.net.  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.


Question by:muligan
  • 2

Expert Comment

ID: 16437145
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.

LVL 25

Expert Comment

ID: 16445276
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:


Author Comment

ID: 16447010
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.

Accepted Solution

jrs_50 earned 2000 total points
ID: 16447729
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.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question