Subscribe Bookmark RSS Feed

Copy File() Doesn't Overwrite

djhanson

Community Trekker

Joined:

Jun 23, 2011

Just fyi, Copy File() does not appear to overwrite.  If the destination file already exists the log will show a zero instead.  There also does not appear to be any switch possible (e.g. 1 = overwrite, 0 = no overwrite).

So I'm resorting to: Delete File() then Copy File() for cases where I want it to overwrite an existing destination file.

Just passing this along in case it help others.  I do appreciate these relatively new file utilities, they come in handy for sure. DJ

4 REPLIES
msharp

Super User

Joined:

Jul 28, 2015

confirmed:

for(i=1,i<=2,i++,

  text = "test" || char(i);

  save text file("C:\TEMP\test.txt", text);

  copy = copy file("C:\TEMP\test.txt", "C:\TEMP\test2.txt");

  print(copy);

  text2 = load text file("C:\TEMP\test.txt");

  text3 = load text file("C:\TEMP\test2.txt");

  print(text2);

  print(text3);

)

//log

1

"test1"

"test1"

0

"test2"

"test1"

djhanson

Community Trekker

Joined:

Jun 23, 2011

I'm just bumping this up in case there's a solution.  Problem is, having to Delete File () prior to Copy File () can take a long time...in my case 10 sec and that's for a very small file size.

 

If anyone knows any tricks to make Copy File () overwrite a file if it exists, let me know!  thanks, DJ

txnelson

Super User

Joined:

Jun 22, 2012

I do not have a solution, but I do want to encourage you to report the issue to

     support@jmp.com

Jim
stephen_pearson

Community Trekker

Joined:

Oct 6, 2014

The save file functions do overwrite provided the target file is not being accessed by another program. Would a read file/write file JSL script allow your to overcome the current limitations of the copy file function?