Announcement

Collapse
No announcement yet.

bat to copy file and append date - HELP

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • bat to copy file and append date - HELP

    hello,

    i have a bat script file which i have worked to functioning for the most part, but not the way i want it to.

    the bat script below creates a directory which is named by the date with the source file, but i need the bat to create the copy of the source file with the date appended instead. this does work for the time being, but i need it to be full working the way I need it to:

    @echo off
    :: variables
    set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4%
    set drive=D:\Adjility-Netsuite API
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /K /O


    echo ### Backing up Netsuite Broker.csv file...
    %backupcmd% "D:\SecurePay\Send\broker.csv" "%drive%\Backup Broker File\%mydate%\"


    echo Backup Complete!
    ::@pause



    i have tried the bat script below, which does exactly what i want it to do. only thing is that the bat haults during the process to ask "Does destination specify a file name or directory name......" i need the bat to complete without any interuptions/intervention automatically:

    @echo off
    :: variables
    set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4%
    set drive=D:\Adjility-Netsuite API
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /K /O


    echo ### Backing up Netsuite Broker.csv file...
    %backupcmd% "D:\SecurePay\Send\broker.csv" "%drive%\Backup Broker File\%mydate%
    broker.csv"

    echo Backup Complete!
    ::@pause


    PLEASE HELP

    Thanx in advance.

    justin

  • #2
    Re: bat to copy file and append date - HELP

    Code:
    @echo off
    :: variables
    set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4% 
    set drive="D:\Adjility-Netsuite API"
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /K /O 
    
    echo ### Backing up Netsuite Broker.csv file...
    %backupcmd% "D:\SecurePay\Send\broker.csv" "%drive%\Backup Broker File\%mydate%broker.csv"
    
    echo Backup Complete!
    ::@pause
    Try that or this

    Code:
    @echo off
    :: variables
    set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4% 
    set drive=D:\Adjility-Netsuite_API
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /K /O 
    
    echo ### Backing up Netsuite Broker.csv file...
    %backupcmd% "D:\SecurePay\Send\broker.csv" "%drive%\Backup Broker File\%mydate%broker.csv"
    
    echo Backup Complete!
    ::@pause

    Comment


    • #3
      Re: bat to copy file and append date - HELP

      i will give them a shot.

      thank you so much for your input, it is greatly appreciated.

      thanx,

      justin

      Comment


      • #4
        Re: bat to copy file and append date - HELP

        You want to copy file D:\SecurePay\Send\broker.csv to D:\Adjility-Netsuite API\Backup Broker File\<today's date>\.

        Try this 3-line script.


        Code:
         
        # Script CopyTodaysFile.txt
        var str date
        set $date = { chex "8]" gettime() }
        system -s ("xcopy /s /c /d /e /h /i /r /y /K /O D:/SecurePay/Send/broker.csv D:/Adjility-Netsuite API/Backup Broker File/"+$date+"/broker.csv")



        Script in biterscripting ( http: //www .biterscripting .com[/URL] ) . Save in file "C:/Scripts/CopyTodaysFile.txt", and run with this command.



        Code:
        script "C:/Scripts/CopyTodaysFile.txt
        "
        Last edited by Rems; 29th June 2010, 18:26. Reason: live url removed by mod

        Comment


        • #5
          Re: bat to copy file and append date - HELP

          To copy a file with xcopy.exe and rename the destination file with the same command line - you must use at leased one wildcard in the destination file name. This assumes that destination must be a FILE.

          In the sample below the file extension of the source file is replaced with a wildcard sign in the name for the destination file (I'm using a For-Do statement here to do this). The datestamp is added to the new file name.

          Batch sample:
          Code:
          @echo off
          
          :: Datestamp (8 digets)
          for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
             for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
               (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yyyy=%%p)))
          
          :: variables
          Set "mydate=%yyyy%_%mm%_%dd%"
          set "backupcmd=xcopy.exe /e /i /c /d /h /r /y /K /O"
          Set "srcFile=D:\SecurePay\Send\broker.csv"
          For %%! in ("%srcFile%") Do (
             Set destFile=D:\Adjility-Netsuite API\%mydate%, %%~n!.*)
          
          %backupcmd% "%srcFile%" "%destFile%" &&(
             echo Backup processed.)||(echo xCopy syntax error)
          
          pause

          Alternative:
          For the batch you showed you alternatively could pipe the result of "echo F" to the command line (F=file, D=directory. OS language depended!!):
          Code:
          echo F | %backupcmd% "D:\SecurePay\Send\broker.csv" "%drive%\Backup Broker File\%mydate%broker.csv"
          \Rems
          Last edited by Rems; 9th February 2010, 11:25.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment

          Working...
          X