-1

I want to write a lua script that performs file moving in nextcloud 25. Can anyone provide me a script please?

i tried this script that i found somewhere

function file_move(files, dir) -- Check if the file exists if not exists(file) then return nil end

-- Get the file name and extension local file_name, file_extension = file.name(file):match("(.+)%.(.+)")

-- Set the destination folder and new name dir = dir or file.parent(file) -- new_name = new_name or file_name

-- Construct the destination path local destination_path = dir .. "/" .. new_name .. "." .. file_extension

-- Move the file local success, error_msg = file_move(file, destination_path)

if success then -- Return the updated file node return dir else -- Return nil if an error occurred return nil end end

1 Answers1

0

I found the solution here

An example script:

input_files = get_input_files()
if (#input_files ~= 1) then
  abort("More than one file was selected.")
end
file = input_files[1]
destination_path = "/destination_folder"
success = file_move(file, destination_path)
if (success) then
  add_message("File moved!")
else
  abort("Failed to move file")
end
arkascha
  • 41,620
  • 7
  • 58
  • 90