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

Posted on 2006-04-12
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  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
    LVL 4

    Expert Comment

    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

    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

    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.
    LVL 4

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Add mobile access to browser application 3 106
    triangle challenge 4 34
    countX 22 48
    firstChar challenge 13 53
    You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now