make a copy of a file from within Navision

How can a make a copy of a file? (the file can have a long filename or exist in a path with spaces). Thought this must be simple, but it was not… Have tried to use: - SHELL(copy [source] [destination]); But then I get the error that the file “copy” does not exist. - SHELL(command /C copy [source] [destination]); But then I can not handle files in a path with spaces (such as “\program files”). - SHELL(xcopy [source] [destination]); But then I get a question from XCOPY if the destination is a file or a folder, which I can not answer, with the SHELL command (?). - I found out that if I first create the destination file, XCOPY will not ask if destination is a file or a folder, and if I pass the /Y parameter the file is overwritten without questions. But if I try to use file.create([destination]); SHELL(xcopy [source] [destination] /Y); I get an error in Navision “Error XX in Module XX”. Anyone got any ideas about how perform such a simple task as making a damn copy of a file???

Hi Frederik, - SHELL(command /C copy [source] [destination]); as you are using you need to use the short, 8-character names of dos, therefore you cannot use “\Program Files” but instead using “\Progra~1” works fine. It’s not very comfortable but it works. (example: RetCode := SHELL(Command,’/c’,‘copy D:\diesis~1\rep-te~1.fob D:’); - second idea: you might be able to use an automation object of Windows that includes the copy feature, though I haven’t found one myself… Saludos Nils

C/AL has a built in function to copy files - check out the help.

Ups, I did’t think of that one… good point, Jack. and it is as easy as this (see function file.COPY for more details): COPY(‘D:\this is a test\report test.fob’, ‘E:\rep-test.fob’); Saludos Nils

Hello NilsM! Problem is that I get the filepath from a file-open dialog, where the user select a file. It is this file selected by the user I want to make a copy of. So to be able to use copy with I would need some conversion function in Navision that converts a filepath to a short 8-character filepath.

Well, eeeh… You’re right. Maybe I should go and see the optician. Thankyou guys!