win7 listdir 'computer' folder

This is the place for queries that don't fit in any of the other categories.

win7 listdir 'computer' folder

Postby verstapp » Mon Jul 15, 2013 3:22 am

hi. while windows explorer has no problem displaying the 'computer' folder on my win7 box, i seem to be unable to listdir() it.
any ideas?

verstapp
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am

Re: win7 listdir 'computer' folder

Postby metulburr » Mon Jul 15, 2013 4:52 am

hi. while windows explorer has no problem displaying the 'computer' folder on my win7 box, i seem to be unable to listdir() it.


read this
What is the exact code you are trying?
What is the exact Traceback error? Or what is the output?

i seem to be unable to listdir() it

this does not mean much
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1389
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: win7 listdir 'computer' folder

Postby verstapp » Mon Jul 15, 2013 4:58 am

>>> c='computer'
>>> x=os.listdir(c)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
x=os.listdir(c)
WindowsError: [Error 3] The system cannot find the path specified: 'computer/*.*'
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am

Re: win7 listdir 'computer' folder

Postby metulburr » Mon Jul 15, 2013 5:10 am

c='computer'

os.listdir() takes a path. the string "computer" is not a path. The path would be something like
Code: Select all
c:\

Code: Select all
D:\\StatsScript\\download\\AppStats

or in linux:
Code: Select all
/home/metulburr


the dot '.' will give the path of current directory:
Code: Select all
import os

print(os.listdir('.'))
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1389
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: win7 listdir 'computer' folder

Postby verstapp » Mon Jul 15, 2013 5:25 am

my problem isn't with using listdir, it is with finding the 'computer' folder.
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am

Re: win7 listdir 'computer' folder

Postby micseydel » Mon Jul 15, 2013 5:46 am

It isn't a folder on your computer. It's just a thing Windows does.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1229
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: win7 listdir 'computer' folder

Postby verstapp » Mon Jul 15, 2013 6:02 am

as windows can find/generate it then surely i should be able to too.
local disk, devices with removable storage and network shares appear in there, as does my camera when connected. the end result of this little exercise is to detect when my camera is connected and to upload the pics from it.
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am

Re: win7 listdir 'computer' folder

Postby metulburr » Mon Jul 15, 2013 7:08 am

os.listdir() takes a string that is a directory. "my computer" is not a directory. C:\ displays in my computer is, D:\ also is, your camera also is, but not "my computer". So attempting to list the directory of a non-existing directory (my computer) is a dead end.

I was going to test this and play around with the idea to get a little more info for you
http://stackoverflow.com/questions/4666 ... -connected
but then i realized i already deleted my windows OS from all my computers and i didnt want to modify the windows 7 virtual box running in linux to accept usb's and such. So i will just leave you with the link.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1389
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: win7 listdir 'computer' folder

Postby verstapp » Mon Jul 15, 2013 7:19 am

back in xp days this was so much simpler - a usb device, upon connection, would just get the next drive number, in my case E:.
so i'd just os.walk ('E:') and all would be well.
win7 obviously has a newimproved system.
anyway thanks for your help and i'll head on over to stackoverflow.
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am

Re: win7 listdir 'computer' folder

Postby metulburr » Mon Jul 15, 2013 7:38 am

if 'E:\' was a valid drive, it should work. I was just saying the os.listdir('computer') is not going to list what gets displayed when you open up "my computer"
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1389
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: win7 listdir 'computer' folder

Postby ochichinyezaboombwa » Mon Jul 15, 2013 5:53 pm

micseydel wrote: It's just a thing Windows does.
Reminded me of this:
Yesterday it worked,
today it isn't working:
Windows is like that.


(Here is more.)
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: win7 listdir 'computer' folder

Postby Yoriz » Mon Jul 15, 2013 6:37 pm

To get the list of drives that MyComputer shows you will want to use the win32 module.
Code: Select all
import win32api
import win32file

drive_types = {win32file.DRIVE_UNKNOWN: 'Unknown',
               win32file.DRIVE_NO_ROOT_DIR: 'No Root Directory',
               win32file.DRIVE_REMOVABLE: 'Removable Disk',
               win32file.DRIVE_FIXED: 'Local Disk',
               win32file.DRIVE_REMOTE: 'Network Drive',
               win32file.DRIVE_CDROM: 'Compact Disc',
               win32file.DRIVE_RAMDISK: 'RAM Disk'}

for drive in win32api.GetLogicalDriveStrings().split('\0'):
    if drive:
        drive_type = win32file.GetDriveType(drive)
        print '{} -> {}'.format(drive, drive_types[drive_type])

Example output
Code: Select all
C:\ -> Local Disk
D:\ -> Compact Disc
E:\ -> Removable Disk
F:\ -> Local Disk
G:\ -> Local Disk
Y:\ -> Local Disk
Z:\ -> Local Disk
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 781
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: win7 listdir 'computer' folder

Postby verstapp » Wed Jul 17, 2013 10:05 am

hi Yoriz.
thanks for your efforts, but as i mentioned above, in the newimproved win7 system, a usb-attached camera doesn't appear as a named drive [as it did in xp where my previous code worked well], but as an entry in my computer called [in my case] 'canon powershot sx130is'.
verstapp
 
Posts: 9
Joined: Mon Jul 15, 2013 3:08 am


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], W3C [Linkcheck] and 4 guests