Announcement

Collapse
No announcement yet.

Copy File 20 times, and rename with time

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

  • Copy File 20 times, and rename with time

    Hello,

    I am trying to copy a file 20 times, and then give it a new name with the current time and seconds. I have got this so far, but I am getting a "path not found" error, although I know it is the right path. Any ideas?

    Code:
    Dim objfso, CopyNumber, objFileCopy, strFilePath, strDestination
    
    strFilePath = "C:\Documents and Settings\sdicicco\Desktop\Test\KILLDISK.LOG"
    strDestination ="C:\Documents and Settings\sdicicco\Desktop\Test\New Folder\"
    
    Set objfso = CreateObject("Scripting.FileSystemObject")
    Set objFileCopy = objfso.GetFile(strFilePath)
    
    CopyNumber = 1
    
    Do Until CopyNumber = 20
    Newname = (Now) & ".log"
    objFileCopy.Copy strDestination & Newname
    CopyNumber = CopyNumber + 1
    Loop
    
    msgbox "Copying Done!"
    WScript.Quit

  • #2
    Re: Copy File 20 times, and rename with time

    I took out "Newname" and that let the script run...

    "objFileCopy.Copy strDestination"

    so that is whats causing the problem...although my counter didn't seem to work either...

    Comment


    • #3
      Re: Copy File 20 times, and rename with time

      For whatever reason, the time functions were not working...but this works:

      Dim objfso, CopyNumber, objFileCopy, strFilePath, strDestination, strNewname

      strFilePath = "C:\Documents and Settings\sdicicco\Desktop\Test\KILLDISK.LOG"
      strDestination ="C:\Documents and Settings\sdicicco\Desktop\Test\New Folder\"

      Set objfso = CreateObject("Scripting.FileSystemObject")
      Set objFileCopy = objfso.GetFile(strFilePath)

      CopyNumber = 1

      Do Until CopyNumber = 20
      objFileCopy.Copy strDestination & "XMLconfig" & CopyNumber & ".xml"
      CopyNumber = CopyNumber + 1
      Loop

      msgbox "Copying Done!"
      WScript.Quit

      Comment


      • #4
        Re: Copy File 20 times, and rename with time

        The function Now() is Ok, but you cannot use the output as it is, for folder and file names, because is contain signs that are not alowed in names.
        Therefore you must replace the default date and time separators.
        Also.. the default date format is not sortable, you may want to change that format too.

        sample format yyyymmdd-hhmmss
        Code:
        ' note:
        ' The format of the month#_of_the_year 
        ' and the format of the day#_of_the_month, 
        ' these are not always a 2-digit notation.
        ' so, incase you do not add date separators, then: 
        '    e.g. 2008111 could be, the first of September OR 11th of January
        '
        ' The sample below deals with that problem;
        
        dt = Now()
        dtStamp = Year(dt)*1e4 + Month(dt)*1e2 + Day(dt) & "-" _
          & right(1e6 + Hour(dt)*1e4 + Minute(dt)*1e2 + Second(dt),6)
        
        'Explanation:
        '	[e.g. Today = April 6 2008 ]
        ' Year(dt) * 1000	= 20080000
        ' Month(dt) * 100	= 00000400
        ' Day(dt) * 1		= 00000006
        ' 			----------- +
        ' 		    SOM	: 20080406

        \Rems

        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