General discussion

  • Creator
    Topic
  • #2131988

    Find a copy a file with File.Copy method

    Locked

    by pete.zerger ·

    I have a vbscript that I use to parse all log the files in a directory to find the log file created yesterday (using DateCreated property). The script currently zips the logs, but I want to change that.

    Once the file has been found, I want to copy it locally to a different directory and rename it in the process. I know how to use File.Copy when I already know file name, but how to I tell File.Copy to copy the file when the I can’t give it an explicit name??

    (the log file has a different name every day)

All Comments

  • Author
    Replies
    • #3570273

      Find a copy a file with File.Copy method

      by dklippert ·

      In reply to Find a copy a file with File.Copy method

      Tried wildcards?

      “COPY FILE creates a duplicate of the file whose name is specified in FileName1. You can use COPY FILE to copy any type of file. The file to be copied cannot be open. You must include the extensions for both the source file name FileName1 and destination file name FileName2.

      FileName1 and FileName2 can contain wildcard characters such as * and ?. For example, to create backup copies of all program files with the extension .prg in the current directory, issue COPY FILE *.PRG TO *.BAK.”

      You can can concatenate the destination file with a variable and or use a for next loop to give multiple file unique names.

    • #3548248

      Find a copy a file with File.Copy method

      by c1980 ·

      In reply to Find a copy a file with File.Copy method

      I’ve do not use vbscript but maybe you can use this logic that I would use in VB6 for the same problem:

      If I know the directory, I can use the Dir command to get the name of a file OR the names of the files in a specific directory.
      If I call theDir command, passing to it the path with-out a file name, it will return the path and name of the first file in the directory, which then I can parse to get the file name. If I the call Dir again, it will return the NEXT file in that directory, and so on until I have looped through all of the files. I can use a place holder ( *.Doc ), in order to return files of a specific type. I can get the properties of each file with-in the loop to check, for instance, the date created. Based on this, I canget the file name, and then do the copy, for the last, file based on date,( or for all files if the criteria is for a specific date and not just the last created file), and or extension.

      Hope this helps!

      • #3559382

        Find a copy a file with File.Copy method

        by pete.zerger ·

        In reply to Find a copy a file with File.Copy method

        Thanks for your effort. The answer follows

        For Each File in SubFiles

        SourceFile = File.DateLastModified

        ‘Now copy and rename that file

        If DateDiff(“d”,SourceFile,Date())=2 Then

        FileSystem.Copyfile File,”c:\temp\webstats.csv”,True

        End If
        Next

    • #3559922

      Find a copy a file with File.Copy method

      by 3wadman ·

      In reply to Find a copy a file with File.Copy method

      Better control than Copy!!
      strFileName = “c:\InetPub\domain.com\logfile.txt”

      • #3559383

        Find a copy a file with File.Copy method

        by pete.zerger ·

        In reply to Find a copy a file with File.Copy method

        Thanks for your effort. The answer follows

        For Each File in SubFiles

        SourceFile = File.DateLastModified

        ‘Now copy and rename that file

        If DateDiff(“d”,SourceFile,Date())=2 Then

        FileSystem.Copyfile File,”c:\temp\webstats.csv”,True

        End If
        Next

    • #3559381

      Find a copy a file with File.Copy method

      by pete.zerger ·

      In reply to Find a copy a file with File.Copy method

      This question was closed by the author

Viewing 3 reply threads