Can anyone help me to create vbscript for copying a file from one folder to another folder and then rename the copied file by appending date and time to the file name.

I need to copy my server log file to another folder up on completion of one log file and then rename the copied file adding date and time to the file name

Source : C:\\Server\Logs

Destination : Can be selected by user using .BrowseForFolder

Log file name : Server_logs_23.txt("23" is the log number which will change from 1 to 30)

One log file will be completed in 2 minutes and log writing will be moved to next file by adding one(that means if Server_logs_23.txt is completed then server will starts writing logs in Server_logs_24.txt  till Server_logs_30.txt, if log is completed then it will starts writing in log_1)

Below is the flow chat fr the script log_1 

2 Comments   [ + ] Show comments
  • Sounds like a school assignment, lol.
    Can do this in PowerShell, guess you need it in VBS. - rileyz 4 years ago
  • Thank you for making it simple as school assignment. First of all I am not an expert in coding(If I am , i wont ask here). I need this in Vbscript or atleast in batch - anonymous_148040 4 years ago

Answers (3)

Posted by: SMal.tmcc 4 years ago
Red Belt

Batch with user input:

set /p Input=Enter destination path:
move install.log "%Input%\install_%date:~-4,4%%date:~-7,2%%date:~-10,2%_.log"

command line:
move install.log "c:\someplaceelse\install_%date:~-4,4%%date:~-7,2%%date:~-10,2%_.log"

  • didn't work - anonymous_148040 4 years ago
    • Oops I forgot time, what else does not work?
      move c:\temp\install.log "c:\temp\tempmove\install_%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~0,2%_%time:~3,2%.log" - SMal.tmcc 4 years ago
Posted by: SMal.tmcc 4 years ago
Red Belt

  • this will move only one file, i need to move multiple files according to my input.

    For example I will input a string "log_12" , code should search for that string in list of files in the source folder and if a match found then copy that file to another location with date and time. This process should be continuous(means it should be in loop until i stop it ) - anonymous_148040 4 years ago
Posted by: SMal.tmcc 4 years ago
Red Belt

how about this then

do a batch with input for target

rename Install_*.log "Install_*_%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~0,2%_%time:~3,2%.log"

move *.log %1

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ