This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DaKillerBear1's profile picture

How do I remotley access a disk drive?

Started by DaKillerBear1, 14 February 2015 - 08:27 PM
DaKillerBear1 #1
Posted 14 February 2015 - 09:27 PM
Well, I'm new to CC and, well I want to try to make a "server rooom" which is my way of saying "six disk drives connected together by a networking cable" but how do I access those disk drives?? And yes, I have connected the Wired modems (to the computer and all disk drives) and switched them on. And I know that if the disk drive is connected direktly to the computer (side by side) that you can just do "cd disk" and it will access the disk. But i can't see my disk drives! Is it even possible to acces a disk drive outside a program in this way? I hope you understand since I need help ASAP! Thanks!
KingofGamesYami #2
Posted 14 February 2015 - 11:10 PM
To use a locally attached drive, specify “side” as one of the six sides (e.g. “left”); to use a remote disk drive, specify its name as printed when enabling its modem (e.g. “drive_0”).
http://computercraft.info/wiki/Disk_%28API%29
Bomb Bloke #3
Posted 14 February 2015 - 11:38 PM
Easy method is to just type "ls" into your system. Should show you the names of all attached drives, represented as folders.
DaKillerBear1 #4
Posted 15 February 2015 - 02:48 PM
Oh i forgot to mention, how do i access a drive from a program i know it's local = peripheral.wrap("drive_0") but what do i write after "local"?
Bomb Bloke #5
Posted 15 February 2015 - 10:08 PM
No need to wrap the drive as a peripheral, just use disk.getMountPath().
DaKillerBear1 #6
Posted 17 February 2015 - 04:21 PM
No need to wrap the drive as a peripheral, just use disk.getMountPath().
I looked it up and it returns the path to the disk drive, what can i do with this information?
KingofGamesYami #7
Posted 17 February 2015 - 06:13 PM
The fs api requires a directory to work from. This code will show you all files on all disks connected to your computer.


local disks = {}
for _, v in ipairs( peripheral.getNames() ) do
   if peripheral.getType( v )  == "disk_drive" and disk.isPresent( v ) and disk.hasData( v ) then
     disks[ v ] = { fs.list( disk.getMountPath( v ) }
   end
end

for k, v in pairs( disks ) do
  print( k )
  textutils.pagedTabulate( v )
end

Edit: added a check for data
Edited on 17 February 2015 - 05:15 PM
Bomb Bloke #8
Posted 17 February 2015 - 11:31 PM
I looked it up and it returns the path to the disk drive, what can i do with this information?

combine it with a filename and open a file handle or something?

Perhaps it'd be better if you explained what you want to do with your drive.
DaKillerBear1 #9
Posted 18 February 2015 - 04:16 PM
Well i want to access a disk drive through a network cable. Without being in a program.
Lyqyd #10
Posted 18 February 2015 - 04:54 PM
If you have the modems attached to both the computer and the disk drive, and are using fewer than 256 networking cables on the network they are on, and have right-clicked the modem on the disk drive (something like "Peripheral drive_0 connected" will pop up in chat and the inner ring will turn red on the modem), any disk you put in the drive will be mounted as a folder on the computer automatically. The first one appears as the folder /disk, then /disk2 etc. You can interact with the files in these folders just like any other file on the computer.