luafilesystem icon indicating copy to clipboard operation
luafilesystem copied to clipboard

Copying/moving files

Open mystery-z opened this issue 2 years ago • 5 comments

Is there any way to copy/move files using LFS?

I found this from a couple years ago asking for this very feature.

Any updates? And if not what are the reasons this hasn't been implemented yet?

mystery-z avatar Jul 05 '22 19:07 mystery-z

@hishamhm Really really sorry for the @ but you seem pretty active here, maybe you could provide a response (if I may humbly ask for this feature).

Thanks!

mystery-z avatar Jul 05 '22 19:07 mystery-z

It can be done in pure Lua I think. That said; if you can contribute a PR, that would be most welcome I think.

Tieske avatar Jul 15 '22 07:07 Tieske

@Tieske yes, it can. I have similar pure-Lua code in luarocks.fs.* using lfs. Might even move it out of there and into an lfs/util.lua module here, or something.

hishamhm avatar Jul 15 '22 18:07 hishamhm

@Tieske As far as my research goes, the way to do it in pure lua is to use os.execute, but the problem with that is that Unix and Windows have different commands, so the OS needs to be checked first and then there can be an if...then...elseif... statement to switch depending on the OS.

And for files that can be opened using the io.read can be done by making another file (in the destination directory) and copying over the contents.

Is this something similar to what you mean?

@hishamhm Also could you copy and paste a snippet of your code here? It would really help if I could see how you did this. Thanks!

mystery-z avatar Jul 15 '22 18:07 mystery-z

And for files that can be opened using the io.read can be done by making another file (in the destination directory) and copying over the contents.

Yes, this is what the LuaRocks code does for pure-Lua copying, and os.rename can be used for moving. Using lfs to create folders, there's no need to os.execute.

hishamhm avatar Jul 15 '22 19:07 hishamhm