2 Replies - 493 Views - Last Post: 30 October 2013 - 10:02 PM Rate Topic: -----

#1 Gamegoofs2  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 15-April 09

Splitting Drive Letters

Posted 25 October 2013 - 04:15 PM

I'm trying to grab all the drive letters for the drives connected to the computer. I want to split the string returned so I can check each drive for something specific. For some reason those I get a funky return when I say "text.split()"

import win32api, win32file

#Grab drive letters
drives = win32api.GetLogicalDriveStrings()

#Split string up
driveSplit = drives.split()

print driveSplit


When I print drives I get "C:\ D:\ E:\ I:\" when I print driveSplit I get this ['C:\\\x00D:\\\x00E:\\\x00I:\\\x00']
What am I doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Splitting Drive Letters

#2 witeboy724  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 35
  • Joined: 21-June 12

Re: Splitting Drive Letters

Posted 27 October 2013 - 12:57 PM

This is what I've done before. When you have it split, try using ('\000') to remove those characters along with a [:-1] to leave off the last blank entry. Hope this works for you too

import win32api

drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
print drives


Was This Post Helpful? 0
  • +
  • -

#3 Gamegoofs2  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 15-April 09

Re: Splitting Drive Letters

Posted 30 October 2013 - 10:02 PM

Thanks! That worked ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1