• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: guess the file size of compressed file from the original
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guess the file size of compressed file from the original


  • Subject: Re: guess the file size of compressed file from the original
  • From: Graff <email@hidden>
  • Date: Sat, 26 Jun 2004 00:41:39 -0400

One way of doing it is to use the shell tool "wc". The command "wc -c" will accept information from standard input and count up the bytes. So if you pipe the results of ditto into it you will get the resulting file size. Here's the shell command:

/usr/bin/ditto -c -k --sequesterRsrc /path/to/file - | wc -c

By putting a dash (-) as the output file for ditto it will dump its output to standard out, which you then pipe to the wc tool

Here it is in AppleScript:
----
set sourceFile to (choose file)
set sourcePosix to quoted form of (POSIX path of sourceFile)
set dittoSize to do shell script "/usr/bin/ditto -c -k --sequesterRsrc " & sourcePosix & " - | wc -c"

{(size of (info for sourceFile)) as integer, dittoSize as integer}
----

Note that this is the actual size of the file, not the amount of space the file will take up on disk. That will depend on the block size for your volume. It will almost always be slightly more than the actual size of the file. I'm not sure what the standard block size usually is but I know it is usually anywhere from 512 bytes to 4 kilobytes in size. I believe it is commonly 4 kb. This means that if your block size is 4 kb and you have a file that is 5 kb in size then the file system will round up and the file will take up 8 kb on the volume. For files that are over 100 kb this really doesn't matter much, this is especially true for files 1 mb and larger.

- Ken

On Jun 25, 2004, at 1:37 PM, Bill wrote:

The shell command ditto can compress file and preserve the resource forks, so, is it possible to guess the file size of the compressed *.zip from the original file, by applescript?

eg.:

set sourceFile to (choose file)
set tmpZip to (POSIX path of (path to desktop) & "archive.zip")
do shell script "/usr/bin/ditto -c -k --sequesterRsrc " & quoted form of (POSIX path of sourceFile) & space & tmpZip

{size of (info for sourceFile), size of (info for (tmpZip as POSIX file as alias))}
-- {2.4258E+4, 1.9357E+4}

sourceFile is a pdf, size is 24KB, size of the archive.zip is ~20KB

In other words, given the file type & using ditto, can we estimate the size of zipped file?
{kind:"PDF Document",size:2.4258E+4} => {kind:"ZIP archive", size: ?}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >guess the file size of compressed file from the original (From: Bill <email@hidden>)

  • Prev by Date: Re: iSub Toggle
  • Next by Date: Re: Finder window sidebar
  • Previous by thread: guess the file size of compressed file from the original
  • Next by thread: Re: guess the file size of compressed file from the original
  • Index(es):
    • Date
    • Thread