Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Atomicos

How copy files with percent output?

Question

1 answer to this question

Recommended Posts

  • 1

You want a progress bar for the file transfer via modems?

There is no built-in method available, so you need custom scripts for this.

My approach would start with calculating the file's size and transmitting it to the receiving computer. Then the file is split into packets and transferred; by the size of the arriving packets the progress can easily be calculated.

The remaining question is how to split the file. You could either send line by line or send a fixed number of bytes. Depending on your choice, the calculation method for the file size will vary.

Number of lines:

local n = 0  -- number of your lines

for _ in io.lines("path/to/file") do
  n = n + 1
end

Number of bytes:

-- Method 1:

local function filesize (file)
  local pos = file:seek()
  local size = file:seek("end")
  file:seek("set", pos)
  return size
end

-- open file and call function with file
local f = assert(io.open("path/to/file"))
local n = filesize(f)

-- Method 2:

local f = assert(io.open("path/to/file"))
local data = f:read("*all")
local size = #data

The only thing you then need is a way to display the progress, either by simply printing the percentage or by drawing a more or less detailed progress bar.

I hope in correctly interpreted your question and this gets you started. Feel free to ask if you need further assistance.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.