Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
lmonincx
Creator II
Creator II

how to copy and rename a file in cmd.exe

Hi,

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
simospa
Partner - Specialist
Partner - Specialist

Hi,

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

Simone

Peter_Cammaert
Partner - Champion III
Partner - Champion III

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:

%date:~n,m%

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

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.

Thanks.

Anonymous
Not applicable

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.

https://help.qlik.com/en-US/qlikview/12.1/Subsystems/Client/Content/Scripting/FileFunctions/FileTime...

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.