文件正在保存在文件夹中,如何保存

时间:2013-01-28 10:52:35

标签: file lua corona luafilesystem

我想将文件保存在一个文件夹中,但引起的问题是我的文件存储在文件夹之外,这很烦人。我正在分享我到目前为止所做的一切。

-- get raw path to app's Temporary directory
local doc_path = system.pathForFile( "", system.DocumentsDirectory )

-- change current working directory
local success = lfs.chdir( doc_path ) -- returns true on success
local new_folder_path

if success then
lfs.mkdir( "MyNewFolder" )
new_folder_path = lfs.currentdir() .. "/MyNewFolder"
end

local filePath = system.pathForFile( dataFileName , new_folder_path )
r = media.newRecording(filePath)
--print("new recording has been started with a name"..dataFileName)
r:startRecording()

但我的录制文件不在这个新创建的文件夹中 有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我搜索了一下,最后得到了问题的答案。这是如何在指定文件夹中创建新录音

r = media.newRecording( new_folder_path.."/"..dataFileName )

此行会自动在此文件夹中创建文件,如问题中所述。 system.pathForFile()仅在第二个参数是基本目录(如system.DocumentsDirectory时自动创建文件(因为文档中明确提到第二个参数是常量且它应该只是任何基本目录)。 所以,如果你想创建一个新文件,想要找到文件的路径,你可以在文件名之前附加文件夹名称,如my folder/my file 希望这会有所帮助