Ver Mensaje Individual
  #31 (permalink)  
Antiguo 08/11/2004, 10:11
Avatar de Saruman
Saruman
 
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Calcular el tamaño de un archivo

Una función para saber el tamaño de un archivo (bytes, KB, MB).

la funcion es esta:

Código:
<%
	Function FileSize(Path, FileName, Tipo)
		set FSO = Server.CreateObject("Scripting.FileSystemObject")
		set oFile = FSO.GetFile(Server.MapPath(Path & FileName))
	
		FileSize = oFile.Size
		
		select case Tipo
			case 2:
				FileSize = Round(FileSize / 1024, 2)
			case 3:
				FileSize = Round(FileSize / 1048576, 2)
			case 4:
				FileSize = FileSize & " Bytes"
			case 5:
				FileSize = Round(FileSize / 1024, 2) & " KB"
			case 6:
				FileSize = Round(FileSize / 1048576, 2) & " MB"
			case 7:
				if FileSize > 0 and FileSize < 1024 then
					FileSize = FileSize & " Bytes"
				elseif FileSize >= 1024 and FileSize < 1048576 then
					FileSize = Round(FileSize / 1024, 2) & " KB"
				elseif FileSize >= 1048576 then
					FileSize = Round(FileSize / 1048576, 2) & " MB"
				end if
			case else
				FileSize = FileSize
		end select
		
		set oFile = nothing
		set FSO = nothing
	End Function
%>
Y se llama asi:

Código:
tamano_archivo = FileSize("ruta_del_archivo", "nombre_del_archivo", 1)
Tipos:

tamano_del_archivo_ejemplo = 500000

1 = tamano en bytes (500000)
2 = tamano en Kilo bytes (KB) (488.28)
3 = tamano en Mega bytes (MB) (0.48)
4 = tamano en bytes pero con la palabra bytes (500000 bytes)
5 = tamano en Kilo bytes pero con la palabra KB (488.28 KB)
6 = tamano en Mega bytes pero con la palabra MB (0.48 MB)
6 = tamano automático del peso (bytes, KB o MB).
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.