[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

getting volume names in windows

Alfonso

11/20/2006 10:15:00 PM

Does anyone knows how can you get the volume name of a drive in windows?
I'm writting a program that should get the name of the cd or dvd
inserted in the drive. The user selects a directory using a gtk dialog
(filechooser), and then I have the path of the folder; but when you
select a cd/dvd, you get only the letter of the drive (E:\, D:\,...).

I have tried also File.dirname(name_of_a_file_in_the_dvd). It doesn't
give you the cd/dvd name...

Thank's in advance



______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice...

4 Answers

Jano Svitok

11/21/2006 8:52:00 AM

0

On 11/20/06, Alfonso <rubyeu@yahoo.es> wrote:
> Does anyone knows how can you get the volume name of a drive in windows?
> I'm writting a program that should get the name of the cd or dvd
> inserted in the drive. The user selects a directory using a gtk dialog
> (filechooser), and then I have the path of the folder; but when you
> select a cd/dvd, you get only the letter of the drive (E:\, D:\,...).
>
> I have tried also File.dirname(name_of_a_file_in_the_dvd). It doesn't
> give you the cd/dvd name...
>
> Thank's in advance

I guess there's some WINAPI (use WIN32API) for that, or WScript (COM
-> use WIN32OLE) or WMI (COM). Just google a bit (and see Programming
Ruby how to use those libs).

Alfonso

11/21/2006 3:54:00 PM

0

Jan Svitok escribió:
> On 11/20/06, Alfonso <rubyeu@yahoo.es> wrote:
>> Does anyone knows how can you get the volume name of a drive in windows?
>> I'm writting a program that should get the name of the cd or dvd
>> inserted in the drive. The user selects a directory using a gtk dialog
>> (filechooser), and then I have the path of the folder; but when you
>> select a cd/dvd, you get only the letter of the drive (E:\, D:\,...).
>>
>> I have tried also File.dirname(name_of_a_file_in_the_dvd). It doesn't
>> give you the cd/dvd name...
>>
>> Thank's in advance
>
> I guess there's some WINAPI (use WIN32API) for that, or WScript (COM
> -> use WIN32OLE) or WMI (COM). Just google a bit (and see Programming
> Ruby how to use those libs).
>
>
Thank you very much for the idea, I'm going to have a look at that win32ole


______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice...

Jano Svitok

11/21/2006 9:11:00 PM

0

On 11/21/06, Alfonso <rubyeu@yahoo.es> wrote:
> Jan Svitok escribió:
> > On 11/20/06, Alfonso <rubyeu@yahoo.es> wrote:
> >> Does anyone knows how can you get the volume name of a drive in windows?
> >> I'm writting a program that should get the name of the cd or dvd
> >> inserted in the drive. The user selects a directory using a gtk dialog
> >> (filechooser), and then I have the path of the folder; but when you
> >> select a cd/dvd, you get only the letter of the drive (E:\, D:\,...).
> >>
> >> I have tried also File.dirname(name_of_a_file_in_the_dvd). It doesn't
> >> give you the cd/dvd name...
> >>
> >> Thank's in advance
> >
> > I guess there's some WINAPI (use WIN32API) for that, or WScript (COM
> > -> use WIN32OLE) or WMI (COM). Just google a bit (and see Programming
> > Ruby how to use those libs).
> >
> >
> Thank you very much for the idea, I'm going to have a look at that win32ole

try:

Listing 4.3 Enumerating Disk Drive Properties

1. Set objFSO = CreateObject("Scripting.FileSystemObject")
2. Set colDrives = objFSO.Drives
3. For Each objDrive in colDrives
4. Wscript.Echo "Available space: " & objDrive.AvailableSpace
5. Wscript.Echo "Drive letter: " & objDrive.DriveLetter
6. Wscript.Echo "Drive type: " & objDrive.DriveType
7. Wscript.Echo "File system: " & objDrive.FileSystem
8. Wscript.Echo "Is ready: " & objDrive.IsReady
9. Wscript.Echo "Path: " & objDrive.Path
10. Wscript.Echo "Root folder: " & objDrive.RootFolder
11. Wscript.Echo "Serial number: " & objDrive.SerialNumber
12. Wscript.Echo "Share name: " & objDrive.ShareName
13. Wscript.Echo "Total size: " & objDrive.TotalSize
14. Wscript.Echo "Volume name: " & objDrive.VolumeName
15. Next

When the script in Listing 4.3 runs under CScript, information similar
to the following appears in the command window:

Available space: 10234975744
Drive letter: C
Drive type: 2
File system: NTFS
Free space: 10234975744
Is ready: True
Path: C:
Root folder: C:Serial number: 1343555846
Share name:
Total size: 20398661632
Volume name: Hard Drive

from: http://discuss.develop.com/archives/wa.exe?A2=ind0511d&L=dotnet-winforms&T=0&F=&S=&...

That would be in ruby:

require 'win32ole'

file_system = WIN32OLE.new("Scripting.FileSystemObject")
drives = file_system.Drives
drives.each do |drive|
puts "Available space: #{drive.AvailableSpace}"
puts "Drive letter: #{drive.DriveLetter}"
puts "Drive type: #{drive.DriveType}"
puts "File system: #{drive.FileSystem}"
puts "Is ready: #{drive.IsReady}"
puts "Path: #{drive.Path}"
puts "Root folder: #{drive.RootFolder}"
puts "Serial number: #{drive.SerialNumber}"
puts "Share name: #{drive.ShareName}"
puts "Total size: #{drive.TotalSize}"
puts "Volume name: #{drive.VolumeName}"
end

(beware, not tested code so errors can be there!)

Alfonso

11/21/2006 11:11:00 PM

0

Jan Svitok escribió:
> On 11/21/06, Alfonso <rubyeu@yahoo.es> wrote:
>> Jan Svitok escribió:
>> > On 11/20/06, Alfonso <rubyeu@yahoo.es> wrote:
>> >> Does anyone knows how can you get the volume name of a drive in
>> windows?
>> >> I'm writting a program that should get the name of the cd or dvd
>> >> inserted in the drive. The user selects a directory using a gtk
>> dialog
>> >> (filechooser), and then I have the path of the folder; but when you
>> >> select a cd/dvd, you get only the letter of the drive (E:\, D:\,...).
>> >>
>> >> I have tried also File.dirname(name_of_a_file_in_the_dvd). It doesn't
>> >> give you the cd/dvd name...
>> >>
>> >> Thank's in advance
>> >
>> > I guess there's some WINAPI (use WIN32API) for that, or WScript (COM
>> > -> use WIN32OLE) or WMI (COM). Just google a bit (and see Programming
>> > Ruby how to use those libs).
>> >
>> >
>> Thank you very much for the idea, I'm going to have a look at that
>> win32ole
>
> try:
>
> Listing 4.3 Enumerating Disk Drive Properties
>
> 1. Set objFSO = CreateObject("Scripting.FileSystemObject")
> 2. Set colDrives = objFSO.Drives
> 3. For Each objDrive in colDrives
> 4. Wscript.Echo "Available space: " & objDrive.AvailableSpace
> 5. Wscript.Echo "Drive letter: " & objDrive.DriveLetter
> 6. Wscript.Echo "Drive type: " & objDrive.DriveType
> 7. Wscript.Echo "File system: " & objDrive.FileSystem
> 8. Wscript.Echo "Is ready: " & objDrive.IsReady
> 9. Wscript.Echo "Path: " & objDrive.Path
> 10. Wscript.Echo "Root folder: " & objDrive.RootFolder
> 11. Wscript.Echo "Serial number: " & objDrive.SerialNumber
> 12. Wscript.Echo "Share name: " & objDrive.ShareName
> 13. Wscript.Echo "Total size: " & objDrive.TotalSize
> 14. Wscript.Echo "Volume name: " & objDrive.VolumeName
> 15. Next
>
> When the script in Listing 4.3 runs under CScript, information similar
> to the following appears in the command window:
>
> Available space: 10234975744
> Drive letter: C
> Drive type: 2
> File system: NTFS
> Free space: 10234975744
> Is ready: True
> Path: C:
> Root folder: C:> Serial number: 1343555846
> Share name:
> Total size: 20398661632
> Volume name: Hard Drive
>
> from:
> http://discuss.develop.com/archives/wa.exe?A2=ind0511d&L=dotnet-winforms&T=0&F=&S=&...
>
>
> That would be in ruby:
>
> require 'win32ole'
>
> file_system = WIN32OLE.new("Scripting.FileSystemObject")
> drives = file_system.Drives
> drives.each do |drive|
> puts "Available space: #{drive.AvailableSpace}"
> puts "Drive letter: #{drive.DriveLetter}"
> puts "Drive type: #{drive.DriveType}"
> puts "File system: #{drive.FileSystem}"
> puts "Is ready: #{drive.IsReady}"
> puts "Path: #{drive.Path}"
> puts "Root folder: #{drive.RootFolder}"
> puts "Serial number: #{drive.SerialNumber}"
> puts "Share name: #{drive.ShareName}"
> puts "Total size: #{drive.TotalSize}"
> puts "Volume name: #{drive.VolumeName}"
> end
>
> (beware, not tested code so errors can be there!)
>
>
That's great! Thank's a lot! I see why there is so many people
switching to ruby: the incredible comunity :-)


______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice...