Jump to content

Wildcards In os.chdir

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Syphilis

Syphilis

    Newbie

  • Members
  • Pip
  • 9 posts
What's Up?

So anyway, If you wanted to cd or open certain files with a certain type of extension in cmd, You would use the star or wildcard key (*), But I'm fairly sure python doesn't use them (Well actually fully sure) So the folder I'm trying to change directory too "os.chdir('C:\menolikewindow')", Changes it's name from computer to computer, How could I find out the name and cd into there?

Thanks Bye

#2
manux

manux

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 234 posts
use os.listdir

>>> import os
>>> os.listdir("./")
['My Documents','syphilis infections','pron with marblecake','also the game']

then figure out which are directories by calling os.path.isdir, out of the ones you have selected(like [i for i in os.listdir("./") if "menolikewindow" in i])