How do I convert file size to mb only in JavaScript?
var sizeInMB = (sizeInBytes / (1024*1024)).toFixed(2); alert(sizeInMB + ‘MB’);
var sizeInMB = (sizeInBytes / (1024*1024)).toFixed(2); alert(sizeInMB + ‘MB’);
No, not directly at least. However, you have a number of choices here. Currently your best choices are: Drag and drop files from desktop, see a tutorial. (Link disabled for malware/phishing) Use input type file. Read the contents with the File API or submit the form. Read more on Mozilla Developer Center about reading the … Read more
Measure the necessary time and see yourself. As you say it is absolutely file system dependent. long t1 = System.currentTimeMillis(); …Your File.exists call long t2 = System.currentTimeMillis(); System.out.println(“time: ” + (t2 – t1) + ” ms”); You will see that it will always give you different results, since it depends also on the way your … Read more
I typically create a header filesystem.hpp with the following content: // We haven’t checked which filesystem to include yet #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL // Check for feature test macro for <filesystem> # if defined(__cpp_lib_filesystem) # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 // Check for feature test macro for <experimental/filesystem> # elif defined(__cpp_lib_experimental_filesystem) # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 // We can’t check … Read more
After 3 years and 2 months… I received a lot of points because of this question here on stackoverflow. So yesterday I decided to revisit this topic :). Using fcntl and F_LOG2PHYS is possible to check if files are using same physical blocks or not. So I made an utility using this idea and put … Read more
__file__ as others have said. You may also want to use os.path.realpath to eliminate symlinks: import os os.path.realpath(__file__)
This is a more elegant way: function script_path() local str = debug.getinfo(2, “S”).source:sub(2) return str:match(“(.*/)”) end print(script_path())
The File.Exists method exists primarily for testing for the existence of a file when you do not intend to open the file. For example testing for the existence of a locking file whose very existence tells you something but whose contents are immaterial. If you are going to open the file then you will need … Read more
The other answer is great, but instead of the “rather monstrous” perl script i suggest perl -pe ‘s!([^/]+)$!lc $1!e’ Which will lowercase just the filename part of the path. Edit 1: In fact the entire problem can be solved with: find . | perl -ne ‘s!([^/]+)$!lc $1!e; print if 1 == $seen{$_}++’ Edit 3: I … Read more