elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)  (Leído 3,865 veces)
Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.811



Ver Perfil
[Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)
« en: 31 Marzo 2012, 17:52 pm »



Una utilidad por linea de comandos para convertir entre bytes, kilobytes, megabytes, gigabytes, terabytes, y petabytes.

Citar
Como usarlo:
Código:
CTool.exe {Tamaño} {Unidad} {A unidad}
  Las unidades son: Bytes, KB, MB, GB, TB, PB.

 Ejemplos:

  - Convertir bytes a megabytes:
Código:
CTool 446.777.647.104 Bytes MB

  - Convertir megabytes a kilobytes:
Código:
CTool 44.33 MB KB

  - Convertir petabyte a todas las unidades:
Código:
CTool 1 PB

Algunas imagenes:

   

- El script convertido a EXE:



- Un ejemplo de uso en Batch, Para averiguar el espacio libre en el disco duro:
Código
  1. @Echo OFF
  2. For /f "tokens=3 delims= " %%# in ('Dir ^| find "libres"') do (Set "Bytes=%%#")
  3. For /f "tokens=2 delims==" %%# in ('Ctool %bytes% bytes gb ^| Find "="') do (Echo: Espacio libre en %Homedrive%%%#)

- El script, Codeado en Ruby:
  PD: Quizás no me ha quedado muy "bonito", Repito bastantes cosas que se podrian simplificar xD pero no estoy por la labor de hacerlo, Así como está ya funciona xD.

Código
  1. # -*- coding: UTF-8 -*-
  2.  
  3. # Conversion Tool v0.1
  4. # By Elektro H@cker
  5.  
  6. exit if Object.const_defined?(:Ocra)
  7.  
  8. def logo()
  9. puts "
  10.  _______  _______                __
  11. |   _   ||       |.-----..-----.|  |
  12. |.  1___||.|   | ||  _  ||  _  ||  |
  13. |.  |___ `-|.  |-'|_____||_____||__|
  14. |:  1   |  |:  |
  15. |::.. . |  |::.|    Conversion
  16. `-------'  `---'       Tool
  17.  
  18.  
  19. "
  20. end
  21.  
  22. def help()
  23. print "
  24. How to use it:
  25.  
  26.   #{__FILE__.split('/').last.split('.').first}.exe {Size} {Unit} {To unit}
  27.  
  28.   Units are: Bytes, KB, MB, GB, TB, PB.
  29.  
  30.  
  31. Examples:
  32.  
  33.  - Convert bytes to megabytes:
  34.  
  35.    #{__FILE__.split('/').last.split('.').first}.exe 446.777.647.104 Bytes MB
  36.  
  37.  - Convert megabytes to kilobytes:
  38.  
  39.    #{__FILE__.split('/').last.split('.').first}.exe 44.33 MB KB
  40.  
  41.  - Convert petabyte to all:
  42.  
  43.    #{__FILE__.split('/').last.split('.').first}.exe 1 PB
  44.  
  45. "
  46. Process.exit
  47. end
  48.  
  49. def BytesToUnit (number)
  50.  
  51.  @KILOBYTE   = 1024.0
  52.  @MEGABYTE = 1024.0 * 1024.0
  53.  @GIGABYTE  = 1024.0 * 1024.0 * 1024.0
  54.  @TERABYTE  = 1024.0 * 1024.0 * 1024.0 * 1024.0
  55.  @PETABYTE  = 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
  56.  
  57. @Bytes = number.to_s + " Bytes"
  58.  
  59. @Kilos = (number / @KILOBYTE).to_s
  60.  if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
  61.    @Kilos = "KB too depth"
  62.  elsif  not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
  63.     @Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
  64.   elsif
  65.     @Kilos = "0.0 KB".to_s
  66.  end # Kilos
  67.  
  68. @Megas = (number / @MEGABYTE).to_s
  69.  if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
  70.    @Megas = "MB too depth"
  71.  elsif  not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
  72.     @Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
  73.   elsif
  74.     @Megas = "0.0 MB".to_s
  75.   end # Megas
  76.  
  77. @Gigas = (number / @GIGABYTE).to_s
  78.  if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
  79.    @Gigas = "GB too depth"
  80.  elsif not @Gigas.include? "-"
  81.     @Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
  82.   elsif
  83.     @Gigas = "0.0 GB".to_s
  84.   end # Gigas
  85.  
  86. @Teras = (number / @TERABYTE).to_s
  87.  if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
  88.    @Teras = "TB too depth"
  89.  elsif not @Teras.include? "-"
  90.     @Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
  91.   elsif
  92.     @Teras = "0.0 TB".to_s
  93.   end # Teras
  94.  
  95. @Petas = (number / @PETABYTE).to_s
  96.  if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
  97.    @Petas = "PB too depth"
  98.  elsif not @Petas.include? "-"
  99.     @Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
  100.   elsif
  101.     @Petas = "0.0 PB".to_s
  102.   end # Petas
  103. end
  104.  
  105. def KBToUnit (number)
  106.  
  107.  @BYTE           = 1024.0
  108.  @MEGABYTE = 1024.0
  109.  @GIGABYTE  = 1024.0 * 1024.0
  110.  @TERABYTE  = 1024.0 * 1024.0 * 1024.0
  111.  @PETABYTE  = 1024.0 * 1024.0 * 1024.0 * 1024.0
  112.  
  113. @Bytes = (number * @BYTE).to_s
  114.  if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
  115.    @Bytes = "Bytes too depth"
  116.  elsif @Bytes[0..2].eql? "0.0"
  117.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
  118.  elsif
  119.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
  120.  end # Bytes
  121.  
  122. @Kilos = number.to_s + " KB"
  123.  
  124. @Megas = (number / @MEGABYTE).to_s
  125.  if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
  126.    @Megas = "MB too depth"
  127.  elsif  not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
  128.     @Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
  129.   elsif
  130.     @Megas = "0.0 MB".to_s
  131.   end # Megas
  132.  
  133. @Gigas = (number / @GIGABYTE).to_s
  134.  if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
  135.    @Gigas = "GB too depth"
  136.  elsif not @Gigas.include? "-"
  137.     @Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
  138.   elsif
  139.     @Gigas = "0.0 GB".to_s
  140.   end # Gigas
  141.  
  142. @Teras = (number / @TERABYTE).to_s
  143.  if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
  144.    @Teras = "TB too depth"
  145.  elsif not @Teras.include? "-"
  146.     @Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
  147.   elsif
  148.     @Teras = "0.0 TB".to_s
  149.   end # Teras
  150.  
  151. @Petas = (number / @PETABYTE).to_s
  152.  if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
  153.    @Petas = "PB too depth"
  154.  elsif not @Petas.include? "-"
  155.     @Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
  156.   elsif
  157.     @Petas = "0.0 PB".to_s
  158.   end # Petas
  159. end
  160.  
  161. def MBToUnit (number)
  162.  
  163.  @BYTE           = 1024.0 * 1024.0
  164.  @KILOBYTE   = 1024.0
  165.  @GIGABYTE  = 1024.0
  166.  @TERABYTE  = 1024.0 * 1024.0
  167.  @PETABYTE  = 1024.0 * 1024.0 * 1024.0
  168.  
  169. @Bytes = (number * @BYTE).to_s
  170.  if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
  171.    @Bytes = "Bytes too depth"
  172.  elsif @Bytes[0..2].eql? "0.0"
  173.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
  174.  elsif
  175.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
  176.  end # Bytes
  177.  
  178. @Kilos = (number * @KILOBYTE).to_s
  179.  if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
  180.    @Kilos = "KB too depth"
  181.  elsif  not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
  182.     @Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
  183.   elsif
  184.     @Kilos = "0.0 KB".to_s
  185.  end # Kilos
  186.  
  187. @Megas = number.to_s + " MB"
  188.  
  189. @Gigas = (number / @GIGABYTE).to_s
  190.  if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
  191.    @Gigas = "GB too depth"
  192.  elsif not @Gigas.include? "-"
  193.     @Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
  194.   elsif
  195.     @Gigas = "0.0 GB".to_s
  196.   end # Gigas
  197.  
  198. @Teras = (number / @TERABYTE).to_s
  199.  if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
  200.    @Teras = "TB too depth"
  201.  elsif not @Teras.include? "-"
  202.     @Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
  203.   elsif
  204.     @Teras = "0.0 TB".to_s
  205.   end # Teras
  206.  
  207. @Petas = (number / @PETABYTE).to_s
  208.  if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
  209.    @Petas = "PB too depth"
  210.  elsif not @Petas.include? "-"
  211.     @Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
  212.   elsif
  213.     @Petas = "0.0 PB".to_s
  214.   end # Petas
  215. end
  216.  
  217. def GBToUnit (number)
  218.  
  219.  @BYTE           = 1024.0 * 1024.0 * 1024.0
  220.  @KILOBYTE   = 1024.0 * 1024.0
  221.  @MEGABYTE = 1024.0
  222.  @TERABYTE  = 1024.0
  223.  @PETABYTE  = 1024.0 * 1024.0
  224.  
  225. @Bytes = (number * @BYTE).to_s
  226.  if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
  227.    @Bytes = "Bytes too depth"
  228.  elsif @Bytes[0..2].eql? "0.0"
  229.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
  230.  elsif
  231.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
  232.  end # Bytes
  233.  
  234. @Kilos = (number * @KILOBYTE).to_s
  235.  if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
  236.    @Kilos = "KB too depth"
  237.  elsif  not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
  238.     @Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
  239.   elsif
  240.     @Kilos = "0.0 KB".to_s
  241.  end # Kilos
  242.  
  243. @Megas = (number * @MEGABYTE).to_s
  244.  if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
  245.    @Megas = "MB too depth"
  246.  elsif  not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
  247.     @Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
  248.   elsif
  249.     @Megas = "0.0 MB".to_s
  250.  end # Megas
  251.  
  252. @Gigas = number.to_s + " GB"
  253.  
  254. @Teras = (number / @TERABYTE).to_s
  255.  if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
  256.    @Teras = "TB too depth"
  257.  elsif not @Teras.include? "-"
  258.     @Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
  259.   elsif
  260.     @Teras = "0.0 TB".to_s
  261.   end # Teras
  262.  
  263. @Petas = (number / @PETABYTE).to_s
  264.  if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
  265.    @Petas = "PB too depth"
  266.  elsif not @Petas.include? "-"
  267.     @Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
  268.   elsif
  269.     @Petas = "0.0 PB".to_s
  270.   end # Petas
  271. end
  272.  
  273. def TBToUnit (number)
  274.  
  275.  @BYTE           = 1024.0 * 1024.0 * 1024.0 * 1024.0
  276.  @KILOBYTE   = 1024.0 * 1024.0 * 1024.0
  277.  @MEGABYTE = 1024.0 * 1024.0
  278.  @GIGABYTE  = 1024.0
  279.  @PETABYTE  = 1024.0
  280.  
  281. @Bytes = (number * @BYTE).to_s
  282.  if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
  283.    @Bytes = "Bytes too depth"
  284.  elsif @Bytes[0..2].eql? "0.0"
  285.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
  286.  elsif
  287.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
  288.  end # Bytes
  289.  
  290. @Kilos = (number * @KILOBYTE).to_s
  291.  if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
  292.    @Kilos = "KB too depth"
  293.  elsif  not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
  294.     @Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
  295.   elsif
  296.     @Kilos = "0.0 KB".to_s
  297.  end # Kilos
  298.  
  299. @Megas = (number * @MEGABYTE).to_s
  300.  if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
  301.    @Megas = "MB too depth"
  302.  elsif  not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
  303.     @Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
  304.   elsif
  305.     @Megas = "0.0 MB".to_s
  306.  end # Megas
  307.  
  308. @Gigas = (number * @GIGABYTE).to_s
  309.  if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
  310.    @Gigas = "GB too depth"
  311.  elsif not @Gigas.include? "-"
  312.     @Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
  313.   elsif
  314.     @Gigas = "0.0 GB".to_s
  315.   end # Gigas
  316.  
  317. @Teras = number.to_s + " TB"
  318.  
  319. @Petas = (number / @PETABYTE).to_s
  320.  if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
  321.    @Petas = "PB too depth"
  322.  elsif not @Petas.include? "-"
  323.     @Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
  324.   elsif
  325.     @Petas = "0.0 PB".to_s
  326.   end # Petas
  327. end
  328.  
  329. def PBToUnit (number)
  330.  
  331.  @BYTE          = 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
  332.  @KILOBYTE   = 1024.0 * 1024.0 * 1024.0 * 1024.0
  333.  @MEGABYTE = 1024.0 * 1024.0 * 1024.0
  334.  @GIGABYTE  = 1024.0 * 1024.0
  335.  @TERABYTE  = 1024.0
  336.  
  337. @Bytes = (number * @BYTE).to_s
  338.  if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
  339.    @Bytes = "Bytes too depth"
  340.  elsif @Bytes[0..2].eql? "0.0"
  341.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
  342.  elsif
  343.    @Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
  344.  end # Bytes
  345.  
  346. @Kilos = (number * @KILOBYTE).to_s
  347.  if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
  348.    @Kilos = "KB too depth"
  349.  elsif  not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
  350.     @Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
  351.   elsif
  352.     @Kilos = "0.0 KB".to_s
  353.  end # Kilos
  354.  
  355. @Megas = (number * @MEGABYTE).to_s
  356.  if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
  357.    @Megas = "MB too depth"
  358.  elsif  not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
  359.     @Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
  360.   elsif
  361.     @Megas = "0.0 MB".to_s
  362.  end # Megas
  363.  
  364. @Gigas = (number * @GIGABYTE).to_s
  365.  if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
  366.    @Gigas = "GB too depth"
  367.  elsif not @Gigas.include? "-"
  368.     @Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
  369.   elsif
  370.     @Gigas = "0.0 GB".to_s
  371.   end # Gigas
  372.  
  373. @Teras = (number * @TERABYTE).to_s
  374.  if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
  375.    @Teras = "TB too depth"
  376.  elsif not @Teras.include? "-"
  377.     @Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
  378.   elsif
  379.     @Teras = "0.0 TB".to_s
  380.   end # Teras
  381.  
  382. @Petas = number.to_s + " PB"
  383. end
  384.  
  385. # Error control
  386. def args()
  387.  if ARGV.empty? or ARGV[0] == "/?" or ARGV[1] == nil  or ARGV[2] == nil and not ARGV[1] == "bytes" and not ARGV[1] == "Bytes" and not ARGV[1] == "BYTES" and not ARGV[1] == "kb" and not ARGV[1] == "Kb" and not ARGV[1] == "KB" and not ARGV[1] == "kB" and not ARGV[1] == "mb" and not ARGV[1] == "Mb" and not ARGV[1] == "MB" and not ARGV[1] == "mB" and not ARGV[1] == "gb" and not ARGV[1] == "gB" and not ARGV[1] == "Gb" and not ARGV[1] == "GB" and not ARGV[1] == "tb" and not ARGV[1] == "Tb" and not ARGV[1] == "TB" and not ARGV[1] == "tB" and not ARGV[1] == "pb" and not ARGV[1] == "pB" and not ARGV[1] == "Pb" and not ARGV[1] == "PB"
  388.    help()
  389.  elsif not ARGV[2] == "bytes" and not ARGV[2] == "Bytes" and not ARGV[2] == "BYTES" and not ARGV[2] == "kb" and not ARGV[2] == "Kb" and not ARGV[2] == "KB" and not ARGV[2] == "kB" and not ARGV[2] == "mb" and not ARGV[2] == "Mb" and not ARGV[2] == "MB" and not ARGV[2] == "mB" and not ARGV[2] == "gb" and not ARGV[2] == "gB" and not ARGV[2] == "Gb" and not ARGV[2] == "GB" and not ARGV[2] == "tb" and not ARGV[2] == "Tb" and not ARGV[2] == "TB" and not ARGV[2] == "tB" and not ARGV[2] == "pb" and not ARGV[2] == "pB" and not ARGV[2] == "Pb" and not ARGV[2] == "PB"
  390.    $ToUnit = "all"
  391.  end
  392. end
  393.  
  394. # Process
  395. logo()
  396. args()
  397.  
  398. input = ARGV[0]
  399. unit = ARGV[1]
  400. $ToUnit = ARGV[2]
  401.  
  402. input = input.gsub(',', '.')
  403.  
  404. if not input.length == 6 or not input.length == 5 and not input[-3] == "."
  405.  input = input.gsub('.', '')
  406.  input = input.to_i
  407. elsif
  408.  input = input.to_f
  409. end
  410.  
  411. if unit =~ /bytes/i
  412.  BytesToUnit(input)
  413. elsif unit =~ /kb/i
  414.  KBToUnit(input)
  415. elsif unit =~ /mb/i
  416.  MBToUnit(input)
  417. elsif unit =~ /gb/i
  418.  GBToUnit(input)
  419. elsif unit =~ /tb/i
  420.  TBToUnit(input)
  421. elsif unit =~ /pb/i
  422.  PBToUnit(input)
  423. end
  424.  
  425. if $ToUnit =~ /bytes/i
  426.  puts "#{input} #{unit} = #{@Bytes}"
  427. elsif $ToUnit =~ /kb/i
  428.  puts "#{input} #{unit} = #{@Kilos}"
  429. elsif $ToUnit =~ /mb/i
  430.  puts "#{input} #{unit} = #{@Megas}"
  431. elsif $ToUnit =~ /gb/i
  432.  puts "#{input} #{unit} = #{@Gigas}"
  433. elsif $ToUnit =~ /tb/i
  434.  puts "#{input} #{unit} = #{@Teras}"
  435. elsif $ToUnit =~ /pb/i
  436.  puts "#{input} #{unit} = #{@Petas}"
  437. elsif $ToUnit == nil
  438.  puts "#{input} #{unit} = #{@Bytes}"
  439.  puts "#{input} #{unit} = #{@Kilos}"
  440.  puts "#{input} #{unit} = #{@Megas}"
  441.  puts "#{input} #{unit} = #{@Gigas}"
  442.  puts "#{input} #{unit} = #{@Teras}"
  443.  puts "#{input} #{unit} = #{@Petas}"
  444. end
  445.  
  446. __END__


« Última modificación: 18 Abril 2012, 17:00 pm por EleKtro H@cker » En línea

Runex

Desconectado Desconectado

Mensajes: 192


http://tutogramacion.blogspot.com


Ver Perfil WWW
Re: [Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)
« Respuesta #1 en: 31 Marzo 2012, 18:11 pm »

No tengo ni idea de Batch, pero ¿que largos se hacen los codes no? :).

Buenta tool EleKtro a ver si me animo yo algún dia y la codeo yo en C o Python :)



« Última modificación: 31 Marzo 2012, 23:40 pm por Runex » En línea

"No renunciaría al bambú.
Nunca renuciaría a ti.
No te compares con otros" "El me dijo:
El bambú tenía un propósito diferente al del
helecho, sin embargo eran necesarios y
hacían del bosque un lugar hermoso".
$Edu$


Desconectado Desconectado

Mensajes: 1.842



Ver Perfil
Re: [Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)
« Respuesta #2 en: 31 Marzo 2012, 20:14 pm »

No se Ruby, asi que mucho no me puedo meter pero.. no es demasiado largo? si solamente tiene que dividir o multiplicar tantas veces un numero por 1024. Tendrias que declarar una vez las variables que usaras y hacer 2 funciones, una para ver si no tiene errores y de paso acomodar lo que ingreso el usuario a tu gusto(si puso puntos o no..) y despues la otra funcion para multiplicar o dividir segun pida, con un bucle las veces que haya que hacerlo.

Se que aclaraste que lo hiciste asi porque total ya anda y listo, pero te digo para que lo mejores si queres. Saludos ;)
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.811



Ver Perfil
Re: [Batch] [Ruby] Ctool (Convertidor de unidades Bytes, KB, MB, GB, TB y PB)
« Respuesta #3 en: 31 Marzo 2012, 22:49 pm »

no es demasiado largo?

Tendrias que declarar una vez las variables que usaras y hacer 2 funciones, una para ver si no tiene errores y de paso acomodar lo que ingreso el usuario a tu gusto(si puso puntos o no..) y despues la otra funcion para multiplicar o dividir segun pida, con un bucle las veces que haya que hacerlo.

Se que aclaraste que lo hiciste asi porque total ya anda y listo, pero te digo para que lo mejores si queres. Saludos ;)

Tienes toda la razón, Es largo xD, Voy dominando Ruby poco a poco, Tengo que pensar bien en como puedo simplificar las funciones en una sola o dos como comentas.
Aunque, Creo que no lo haré si no me da por añádirle algo nuevo al code... Como dije, Así ya funca xD

Salu2!
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Batch] Protector de unidades removibles
Scripting
0x0309 0 2,126 Último mensaje 12 Febrero 2009, 20:11 pm
por 0x0309
Script batch para infeccion a traves de Unidades Extraibles
Scripting
LauBuru 4 6,408 Último mensaje 30 Marzo 2009, 22:08 pm
por LauBuru
[Batch] [vbs] ¿Un script para buscar archivos de cero bytes?
Scripting
SuperDraco 0 4,542 Último mensaje 13 Mayo 2011, 20:09 pm
por SuperDraco
[SOURCE] CTool (Conversion Tool, calcula y convierte unidades de tamaño)
.NET (C#, VB.NET, ASP)
Eleкtro 0 1,980 Último mensaje 20 Septiembre 2013, 23:45 pm
por Eleкtro
[APORTE] [BATCH] Convertidor de Temperatura
Scripting
.:Xx4NG3LxX:. 1 2,004 Último mensaje 18 Febrero 2020, 03:34 am
por tincopasan
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines