Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Contributor II

how to copy and rename a file in cmd.exe


Iam using qlikview to make a copy of some of my sources, i do that with cmd.exe /C xcopy $(vExec) /Y;  where $(vExec) is containing "from location" "end location"

this works and makes a copy with the same name of the file

I would like to change the name bij adding the FileDate behind the current name, anyone an idea how to put that in script?

Many thanks!

Linda Monincx

4 Replies
Valued Contributor

Re: how to copy and rename a file in cmd.exe


can you use a macro? If yes, try this:

dim fso

set fso = CreateObject("Scripting.FileSystemObject")

fso.CopyFile "C:\foo.txt", "F:\foo2.txt"

To copy an entire folder you can use:

fso.CopyFile "C:\test\*.*", "F:\a\"

Hope this help


Re: how to copy and rename a file in cmd.exe

Use the RENAME or REN command.

I don't know about the File date (IMHO you should use PowerShell for that) but the current date and time can be used in commandline operations with these two shell variables:

%date%    = returns the current date in the local format

%time%    = returns the current time in the local format

You can lift parts of these strings by using this format:


where n is the start position and m is the length of the substring you need. The same format applies to %time%.

For example, if the current date is printed as "Tu 13/01/2015", then

ECHO %date:~9,4% will get you the year.

Use these variables in the specification for the target name, like

REN ABC.QVD ABC-%date:~9,4%%date:~6,2%%date:~3,2%.QVD

In any case, using CMD.EXE batch files to reach your goal will always seem like a dated and limited method.

Edit: Indices start at 0 (zero)

Not applicable

Re: how to copy and rename a file in cmd.exe

Hi Linda,

I am in need of moving log file from server to my NAS drive. Server has access to NAS. I would like to try your method but not sure how to. Is this what need to be written in the QVW script:

sub ProcLogMove

Set vExec = "C:\IBM\1.qvw.log" "C:\IBM\1\1.qvw.log";

cmd.exe /C xcopy $(vExec) /Y;

End Sub

Please could you guide.


New Contributor

Re: how to copy and rename a file in cmd.exe

You can get the File Time of the source file with the FileTime() function and append it to the target filename in your vExec variable. You can use the date and date format functions to get the file's timestamp into a format you like.


Personally, I would've created separate variables for the source and target locations/filenames to make it easier to track, but your method should be OK as well.

Community Browser