is there a way to move a file? - LUA Scripting - CHDK Forum supplierdeeply

is there a way to move a file?

  • 3 Replies
  • 3618 Views
is there a way to move a file?
« on: 30 / November / 2008, 11:04:38 »
Advertisements
Is there a way to move a file? I have a script that continuously loops, checking for new photos. once it finds the new photo, i want to move and rename it. i've gotten this to work erratically with os.rename which is exactly what i should expect according to the chdk wiki.

is there a method for moving a file?

*

Offline reyalp

  • ******
  • 14080
Re: is there a way to move a file?
« Reply #1 on: 30 / November / 2008, 16:55:16 »
Unfortunately, there isn't. You can rename within a directory, or copy, but there is no move.

In my testing, attempting to rename across directories did not produce the desired result, and may have ended in filesystem corruption (I'm not completely sure, because I tried a whole bunch of stuff.)
Don't forget what the H stands for.

Re: is there a way to move a file?
« Reply #2 on: 30 / November / 2008, 18:22:35 »
how do you copy? there doesn't seem to be a copy command. do you need to read in the file and then save it somewhere else?

*

Offline reyalp

  • ******
  • 14080
Re: is there a way to move a file?
« Reply #3 on: 30 / November / 2008, 18:53:34 »
how do you copy? there doesn't seem to be a copy command. do you need to read in the file and then save it somewhere else?
Yes. Open the source file for reading, the destination file for writing, and copy the contents. If the file is larger than a few hundred KB, you'll need to do it in chunks, as there isn't enough memory to load the whole thing at once.

You'll want to use the form of file:read() that takes a number argument.
Don't forget what the H stands for.


 

Related Topics