batch file help

  • i am making a batch file which will copy a file from one folder to another.

    the syntax is like:

    copy \\171.186.147.94\Apps\MTX\JRun\logs\default-out.log \\171.186.147.94\Apps\MTX\JRun\

    this file is supposed to run daily. Since the destination folder is the same everytime , i need the batch file to overwrite the present file.

    CAn anyone suggest the correct syntax?

    Thanks

    Pankaj

  • How about

    master..xp_cmdshell 'copy \\171.186.147.94\Apps\MTX\JRun\logs\default-out.log \\171.186.147.94\Apps\MTX\JRun\'

  • Adding a /Y after the COPY command should do the trick for you in most environments.

  • Thanks David, it worked for me.

    One more problem:

    Is there any way i can pick up the latest file from a given folder and copy it to a destination?

  • @echo off

    for /f %%v in ('dir /a-d /od /b *.*') do set newest=%%v

    copy /Y %newest% \DestPath

    This should get you started. Change \DestPath to whatever destination you want. This works by enumerating the files in a folder, in date order, ignoring directories and leaving off header info. At the end, "newest" will have the last file that was looped through, which will be the most recent. The copy then uses that as the source parameter.

    Test thoroughly.

     

  • it worked for me.thanks david. u r genius

    One c# problem:

    i have a string 001516. i want to check if it contains colons or not.

    i.e if it is in the format 00:15:16.

    If the string is like 001516 i want to convert it into 00:15:16

    How to do this?

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply