OpenFileDialog box

Well, you probably want the allow_multiple_selects option. Then you’ll get a table of absolute filenames back. Roughly, for each file you would want to do something like this (untested):

local original = io.open(full_path, "rb")
local contents = original:read("*a") -- copy the contents

original:close()

local pos = full_path:find("/") -- or "\\" ... you actually want the last one, so this isn't quite right
local name = full_path:sub(pos + 1) -- get just the file name itself

local new_file = io.open(system.pathForFile(name, system.DocumentsDirectory), "wb")

new_file:write(contents) -- finish the copy
new_file:close()

As I said, it’s a bit rough, but that’s the general idea.

refuse to write the contents

I think the idea is good because it allows me to understand how it works.

based on your idea i ended up doing this, even if i don’t know yet how to find the name as well as the extension of the file. I can still predefine which extension I want to copy.

         
local original = io.open(file, "rb")

local contents = original:read("*a") -- copy the contents
 original:close()

local pos = file:find("\\") -- or "\\" ... you actually want the last one, so this isn't quite right

local new_file = io.open(system.pathForFile( pos..".txt" , system.DocumentsDirectory), "wb")
new_file:write(contents) -- finish the copy
new_file:close()

for those who are interested in this post can modify this line like this:


local new_file = io.open(system.pathForFile( "my_file_name"..pos..".mp4" , system.DocumentsDirectory), "wb")

by adding the name and the extension

now I want to know how to keep the position of the file in memory so that each selected file finds another number like for example (pos+1)

I did a little test, and it looks like you can get the trailing bits like so:

local function GetFilename (s)
  local last, i1, i2

  repeat
    last = i2
    i1, i2 = s:find("[/\\]", i2 and i2 + 1) -- find first "/" or "\\" starting at i2 + 1 (or 1, by default)
  until not i1

  return last and s:sub(last + 1)
end
  
-- Test some different cases:
print(1, GetFilename("TopLevel/MiddleLevel/LowLevel/MyFile.format"))
print(2, GetFilename("NotAFile"))
print(3, GetFilename("A/B\\CC/DDDD\\EE\\F.file"))
print(4, GetFilename("!!!!/"))

There are also some utilities here.

You probably don’t want to use pos as the name since a lot of files could have the slashes at that same position.