Jump to content
UBot Underground

[Solved] get the size of a file (In bytes - MB/Kb )


Recommended Posts

Fellas?

 

I need to get the size of a file (In bytes - MB/Kb ) inside a specific folder.. I realize it can currently only be done via shell commands.

I would be grateful for any help .

 

Thanks.

 

Link to post
Share on other sites

Hi,

 

Sample code:

 

set(#file, "c:\\downloads\\dirlist.txt", "Global")
set(#filename, $replace regular expression(#file, ".*\\\\", $nothing), "Global")
shell("cmd.exe /C dir /-C {#file} | find \"{#filename}\"> c:\\downloads\\file-size.txt")
clear list(%dirresult)
add list to list(%dirresult, $list from text($read file("c:\\downloads\\file-size.txt"), " "), "Delete", "Global")
set(#filesize, 0, "Global")
if($comparison($list total(%dirresult), ">", 2)) {
    then {
        set(#filesize, $list item(%dirresult, 3), "Global")
    }
    else {
    }
}

 

sample-dir-file-size-001.ubot

 

Kevin

  • Like 1
Link to post
Share on other sites

Kevin? You're a Command Line genius!! Thanks a lot man! Couple Of questions if you don't mind?

 

1. where can I start to learn about command line scripting..? any good resources please?

2. why do you do -  if list total is > 2 then set #filesize to list item 3? Why not just set #filesize to list item 3?

 

Thanks a lot Buddy!

Link to post
Share on other sites

Hi,

 

 


1. where can I start to learn about command line scripting..? any good resources please?

I use this site for what commands are available and syntax: http://ss64.com/nt/ I also will use Windows command with /? to provide syntax

I then use search(google/bing) to find code samples.

 

 

 

2. why do you do -  if list total is > 2 then set #filesize to list item 3? Why not just set #filesize to list item 3?

I put the check in just in case the file goes missing while getting file size. Keeps ubot from getting script error on set #filesize to list item 3 when there are 2 or less items in list.

 

Kevin

Link to post
Share on other sites

You could also use "shell function" from my free Advanced Shell plugin, which doesn't need txt file to be saved, instead content if written to UBot variable directly. Besides that it will also run cmd window hidden.

 

You can find more info here:

http://ubotdev.com/free-plugin-advanced-shell#function-shellcommand-prompt-batch-hidden

Link to post
Share on other sites
  • 3 years later...

Hi everybody.

Why is this so complicated? Surely there is an easier way to get the size in bytes of a downloaded file?

Is it not built into ubot studio already?

Link to post
Share on other sites

Hi everybody.

 

Why is this so complicated? Surely there is an easier way to get the size in bytes of a downloaded file?

 

Is it not built into ubot studio already?

 

It is not built into Ubot, there are a couple of plugins that do it though, this one is free:

 

TJ's system commands: http://network.ubotstudio.com/forum/index.php/topic/20737-21-free-plugins-being-given-away/

Link to post
Share on other sites

It is not built into Ubot, there are a couple of plugins that do it though, this one is free:

 

TJ's system commands: http://network.ubotstudio.com/forum/index.php/topic/20737-21-free-plugins-being-given-away/

In the end I used FileFolderCommand plugin to get file size.

 

This function gets the file size of the downloaded file and then, displays the file size in the html + also increases the total data downloaded and also converts the bytes to two decimal MB number.

 

Took me around 6 hours to get it working correctly!

define get_file_size(#file_path) {
    set(#this_file_size,$plugin function("FileFolderCommands.dll", "$get file info", #file_path, "Total Size"),"Global")
    set(#total_data_downloaded_bytes,$add(#total_data_downloaded_bytes,#this_file_size),"Global")
    set(#this_file_size_downloaded_mb,$number format($divide(#this_file_size,1048576)),"Global")
    set(#total_data_downloaded_mb,$number format($divide(#total_data_downloaded_bytes,1048576)),"Global")
}

Thank you everyone for helping me.

  • Like 2
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.

Guest
Reply to this topic...

×   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...