Python Tutorial: OS Module - Use Underlying Operating System Functionality

In this Python Tutorial, we will be going over the 'os' module. The os module allows us to access functionality of the underlying operating system. So we can perform tasks such as: navigate the file system, obtain file information, rename files, search directory trees, fetch environment variables, and many other operations. We will cover a lot of what the os module has to offer in this tutorial, so let's get started.
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Пікірлер: 633

  • @shreyaschavhan5522
    @shreyaschavhan5522 Жыл бұрын

    + os.getcwd() => get current working directory + os.chdir() => change directory + os.listdir() => list directory + os.mkdir() => create a directory + os.makedirs() => make directories recursively + os.rmdir() => remove directory + os.removedirs() => remove directory recursively + os.rename(, ) => rename file + os.stat() => print all info of a file + os.walk() => traverse directory recursively + os.environ => get environment variables + os.path.join(, ) => join path without worrying about / + os.path.basename() => get basename + os.path.dirname() => get dirname + os.path.exists() => check if the path exists or not + os.path.splitext() => split path and file extension + dir(os) => check what methods exists

  • @trigobrooken6260

    @trigobrooken6260

    Жыл бұрын

    thank you best friend

  • @Freddietheking

    @Freddietheking

    10 ай бұрын

    Thank you best friend forever.

  • @manavgora

    @manavgora

    8 ай бұрын

    thanks bro

  • @clarity3208

    @clarity3208

    7 ай бұрын

    Thank you best friend

  • @banchanbet4524

    @banchanbet4524

    7 ай бұрын

    thank you bro

  • @dev_soda8315
    @dev_soda83152 жыл бұрын

    its so sad that this guy has not uploaded any content for over a year now... his tutorials are always the best, most methodically thought out pieces of work on the platform

  • @iluvuvibez6644

    @iluvuvibez6644

    2 жыл бұрын

    You already finished all 143 of the python videos?

  • @Stopinvadingmyhardware

    @Stopinvadingmyhardware

    Жыл бұрын

    Nobody cares that some 15 year old girl working for the Mexican cartels goes around raping dude to try and extort them. Nobody gives a shit.

  • @pinnaclesystemsgroup6472

    @pinnaclesystemsgroup6472

    Жыл бұрын

    I agree .. he is sorely missed

  • @pubgdoremongamer8823

    @pubgdoremongamer8823

    Жыл бұрын

    yeah right 😞

  • @texastitan6567

    @texastitan6567

    Жыл бұрын

    He’s back in action now!

  • @khaled-dz8357
    @khaled-dz8357Ай бұрын

    The best one i have ever seen in teaching coding . Thank you so much man

  • @codaadoc5302
    @codaadoc53026 жыл бұрын

    A tutorial for the sys module would help tremendously. It's difficult to find someone like you who can explain things in such detail as well as show how useful certain things within python can be without half-assing it. Thanks, Corey.

  • @chuanliangjiang7390
    @chuanliangjiang73906 жыл бұрын

    It is very excellent tutorial, much better than some paid python tutorial vedios in Udemy for i in range(1,1000000): print('Thank you so much for sharing this wonderful tutorial')

  • @Pr0G4m3R4u

    @Pr0G4m3R4u

    5 жыл бұрын

    while True: print('Thank you so much for sharing this wonderful tutorial')

  • @greenballscience9514

    @greenballscience9514

    5 жыл бұрын

    (Python script is in c:/pyproj/thankyou.py) Import subsystem Subsystem.call([C://Python//Python.exe, C://pyproj//thankyou.py]) while True: Print(“Thank You So Much”)

  • @Nurtastube

    @Nurtastube

    5 жыл бұрын

    @@Pr0G4m3R4u 😂😂😂

  • @grad6grade

    @grad6grade

    5 жыл бұрын

    @@greenballscience9514 it should be like: import os os.system(''C://Python//Python.exe, C://pyproj//thankyou.py")

  • @oberyn.freezingmoon

    @oberyn.freezingmoon

    4 жыл бұрын

    Error, wait for script to finish.. .. CTRL+C >>> python Greenball_Science.py now you were saying?

  • @jordangillard2637
    @jordangillard26376 жыл бұрын

    Bless your soul Corey! The os module has always been such a pain to learn. When you first see it in code it's so cryptic. Thanks for breaking it down for us!

  • @salkdjfasldkfjsdlk
    @salkdjfasldkfjsdlk7 жыл бұрын

    You are very good at explaining Python modules and their practical uses.

  • @knownwolf
    @knownwolf6 жыл бұрын

    These Python videos are extremely helpful, thank you. I would be grateful if you added chapters. Some of the 10 minute plus videos have a lot of concepts and it would be great to jump back into a specific section when in need of a refresher. Keep up the excellent work and stay Pythonic my friend.

  • @greenballscience9514

    @greenballscience9514

    5 жыл бұрын

    Pythonic?

  • @sameerspl
    @sameerspl6 жыл бұрын

    Thanks Corey. I have started following you.. You make things so simple when it comes to using necessary commands in python.

  • @manuelch4589
    @manuelch45893 жыл бұрын

    Excellent! I really appreciate you sharing so much knowledge at no cost. I am getting it slowly. Thank you

  • @turboromy
    @turboromy6 жыл бұрын

    I was surprised how quick that search was wth os.walk().... and at the same time, wondered why Windows "Find" takes so long. Thanks for the great teachings.

  • @jackieinspace
    @jackieinspace6 жыл бұрын

    Very nice! Tight and down to the core of what is needed!

  • @GihanJayaneththie
    @GihanJayaneththie3 жыл бұрын

    Simple, well organized, great for beginners and informative. Nothing but least speaks English doesn't try to showoff.

  • @seanhogan317
    @seanhogan3178 жыл бұрын

    You are an excellent presenter. The details were very well explained. I learned a lot. Thank you

  • @MattWatsonHarmonica
    @MattWatsonHarmonica Жыл бұрын

    Thank you! I've been using the os module for years and had no idea about os.walk()! Will be putting this to good use!

  • @sreedharIITR
    @sreedharIITR7 жыл бұрын

    For windows users, print (os.environ.get("HOME")) won't work as there is no HOME folder, instead it is USERPROFILE. So, type USERPROFILE instead of HOME.

  • @murakumo222

    @murakumo222

    7 жыл бұрын

    THANKS A LOT!!! i just can't get it work until i saw this comment. but why i can't get it to search other folders? am i only able to search within the same tree?

  • @kostasnikoloutsos5172

    @kostasnikoloutsos5172

    7 жыл бұрын

    Thank you. Now I made this who gives you the desktop path.Pretty useful if you want to create something in the desktop. os.path.join(os.environ.get("USERPROFILE"), "Desktop")

  • @AnthonyMute

    @AnthonyMute

    7 жыл бұрын

    @murakumo222 I don't know if you finally did it but assuming you are referring to os.walk() you could do the os.walk('C:\\Users') replacing the string with whatever directory you want the tree on.

  • @cjz5757

    @cjz5757

    6 жыл бұрын

    Sukant Arora os.environ.get('HOME') works just fine for me

  • @MagnusAnand

    @MagnusAnand

    6 жыл бұрын

    os.environ.get("HOME") worked fine for me in Windows 10

  • @bactran7799
    @bactran77992 жыл бұрын

    every time I need a tutorial video for Python, Corey is always the best one with really well organized, fully information and easily to remember. Thanks a lot Corey

  • @codingisthebest3914

    @codingisthebest3914

    2 жыл бұрын

    Your grammar is wrong, the quote should be, "Every time I need a tutorial video for Python, Corey is always the best one with really well organized, full information and easy to remember. Thanks a lot Corey."

  • @einekleineente1

    @einekleineente1

    2 жыл бұрын

    @@codingisthebest3914 Ich würde mal sagen,dass du ein Klugscheißer bist :)

  • @doodahgurlie

    @doodahgurlie

    Жыл бұрын

    @@codingisthebest3914 Based on his name, he's not American, so it's fine. I agree with what oneLittleDuck wrote in German. LOL

  • @soumyazyx
    @soumyazyx4 жыл бұрын

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  • @user-qn5by5iv7u
    @user-qn5by5iv7u2 жыл бұрын

    It is so demonstrating that you can hardly find any questions in the comments - there are only thanks and insparations 😏 The explanation is so clear that it leaves nothing to ask about 💎 Great job 👍

  • @jwarsame9661
    @jwarsame96617 жыл бұрын

    Thank you Corey Schafer you're the best teacher for pyhton

  • @antonybelkovich7012
    @antonybelkovich70127 жыл бұрын

    Corey , thank YOU at the highest degree !

  • @nameless191
    @nameless1914 жыл бұрын

    Great tutorial straight to point teaching the stuff that actually creates complex programs in a simple way is great

  • @HW-ct1iq
    @HW-ct1iq6 жыл бұрын

    Super good whistlestop tour. Just what I needed.

  • @klamentyne5991
    @klamentyne59913 жыл бұрын

    Extremely useful and explained so well...thanks Corey!

  • @sujithnair232
    @sujithnair2324 жыл бұрын

    for Windows users I used HOMEPATH instead of Home , use SET Command to be able to see all environment variables on CMD print(os.environ.get('HOMEPATH'))

  • @sahajjaiswal1074
    @sahajjaiswal10745 жыл бұрын

    you are much better than my faculty handling python course....

  • @edchelstephens
    @edchelstephens2 жыл бұрын

    Another excellent tutorial! 💯 Thanks a lot Corey 🙏

  • @mansimandlik9013
    @mansimandlik90134 жыл бұрын

    You teach in a interesting way sir ,Thanks Today i have learned all things i was trying to learn from many days

  • @sacredinclinations
    @sacredinclinations8 жыл бұрын

    thanks for this video, clear and helpful and I learnt some new stuff. Please keep on releasing more!

  • @heshankumarasinghe3159
    @heshankumarasinghe31593 жыл бұрын

    An excellent tutorial. Learnt new stuff and this video helped me clear some doubts. Thanks a lot!!!

  • @gregoryfenn1462
    @gregoryfenn14627 жыл бұрын

    Very helpful guide to such an import module :) thanks!

  • @yomajo
    @yomajo5 жыл бұрын

    I never read your descriptions, but after seeing what's on your amazons' wish list, I can tell, you aint no ordinary tutor. Respect. Sharp, evolving mind.

  • @engr.mubasharhanif

    @engr.mubasharhanif

    4 ай бұрын

    hey are you programmer now?

  • @yomajo

    @yomajo

    4 ай бұрын

    @@engr.mubasharhanif Hey. still and will continue to hold myself newbie, but I do have production web app running that I charge the client for.

  • @justgivemethetruth
    @justgivemethetruth7 жыл бұрын

    Good, useful. Lots of stuff in the os module, that is for sure.

  • @zacharysimpson4025
    @zacharysimpson40255 жыл бұрын

    I've been learning python for several months now, and not once did i ever see anything about print(dir())! Like given!

  • @samhhhhh
    @samhhhhh Жыл бұрын

    Excellent explanations and examples, thank you!

  • @luisrosales3058
    @luisrosales30585 жыл бұрын

    Great tutorial. Simple and straight.

  • @vladn.2332
    @vladn.23326 жыл бұрын

    Thank you for the clear and concise explanation!

  • @erfantaghvaei3952
    @erfantaghvaei39523 жыл бұрын

    I love Corey's teaching ... and accent!

  • @cibelless510
    @cibelless5104 жыл бұрын

    OMG, you are really good! Very clear voice and excellent explanation. Thanks for share.

  • @jignareshamwala3401
    @jignareshamwala34017 жыл бұрын

    @Corey Schafer. Your tutorials are awesome! Thank you! :)

  • @ABMA79
    @ABMA793 жыл бұрын

    wonderful explanation.... Thanks a lot for making it more clear brother. you should honestly be a teacher.

  • @carltechnologies2829
    @carltechnologies28294 жыл бұрын

    What a very helpful tutorial, I owe you more than a subscription

  • @JoyDavidson
    @JoyDavidson Жыл бұрын

    Corey, I hope you are well today. 🤙🤙 I have been sober for one year. We got this.

  • @geetavishwakarma4883
    @geetavishwakarma48832 жыл бұрын

    Very informative and helpful. And also very well explained. Thank you

  • @LeirbagIII
    @LeirbagIII2 жыл бұрын

    This si pretty interesting, Corey!! Thanks a lot for your help!

  • @ravialwayswins
    @ravialwayswins6 жыл бұрын

    Really really good stuff Corey!

  • @shriramkaucyk7491
    @shriramkaucyk74915 жыл бұрын

    Awesome one to start with. Just a lot of things.

  • @dilshadomar5078
    @dilshadomar50785 жыл бұрын

    grate video am always around and always learning somthing new from the same video

  • @kelvinmacharia3715
    @kelvinmacharia37155 жыл бұрын

    This a very good tutorial.Thank you Corey

  • @meowmeow70
    @meowmeow703 жыл бұрын

    Thank you Corey. Truly appreciate what you share.

  • @shirzadroohi3000
    @shirzadroohi30004 жыл бұрын

    Thanks, it was very useful for me as a python beginner.

  • @akira_asahi
    @akira_asahi2 жыл бұрын

    Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.

  • @nolevel433
    @nolevel4332 жыл бұрын

    Thats so brilliantly explained. Thanks a lot !!!!

  • @Samuftie
    @Samuftie4 жыл бұрын

    very clear and precise. thank you.

  • @smnsdf
    @smnsdf2 жыл бұрын

    Thanks a lot i started my cyber security journey yesterday , I was advised to learn this module thanks!!!!

  • @suryakantmishra6866
    @suryakantmishra68666 жыл бұрын

    simply awesome.. thanks Corey :)

  • @veeresharadhya1430
    @veeresharadhya14307 жыл бұрын

    please make one tutorial for sys module as well... :-)

  • @ivandrofly

    @ivandrofly

    7 жыл бұрын

    yeah thumbs up!

  • @aditya-mahapatra

    @aditya-mahapatra

    6 жыл бұрын

    Yeah Corey! one for the sys module please! :)

  • @davidreynolds9649

    @davidreynolds9649

    6 жыл бұрын

    and subprocess ;-)

  • @RaviTejaKalidindi

    @RaviTejaKalidindi

    6 жыл бұрын

    and pdb debugger as well if possible :)

  • @beaconbecay1648

    @beaconbecay1648

    5 жыл бұрын

    Veeresh Aradhya yes please. Been struggling with stdin and stdout

  • @Tamer_Gomaa
    @Tamer_Gomaa3 жыл бұрын

    Awesome 👍🏼. Great explanation

  • @juliankercsik5641
    @juliankercsik56414 жыл бұрын

    Thanks Corey bloody good show old chap!!!

  • @bharath695
    @bharath6954 жыл бұрын

    I love this video tutorial just like many :-). As a systems admin, I would like to learn more about the os module. If possible you can make an advanced tutorial on this.

  • @karimkazia
    @karimkazia4 жыл бұрын

    Thank you very very much for these videos. Learning a lot from your videos.

  • @marialoar6923
    @marialoar69234 жыл бұрын

    Great tutorials, extremely helpful and easy to understand! Which Python Interpreter are you using for coding in python? This looks very quick and easy to show putput.

  • @mr.curious1714
    @mr.curious17142 жыл бұрын

    You are the greatest Python teacher

  • @usamashami11
    @usamashami112 жыл бұрын

    Amazing and insightful video!

  • @ranjitrajput9297
    @ranjitrajput92977 жыл бұрын

    Very useful video.Thanks.

  • @heshankumarasinghe3159
    @heshankumarasinghe31593 жыл бұрын

    Thank you for the video..... Learnt new stuff from this.....

  • @MatiasEzelQ
    @MatiasEzelQ7 жыл бұрын

    Amazing the simplicity of python :O

  • @maheshjadhav8118
    @maheshjadhav81186 жыл бұрын

    Awesome tutorial!

  • @Shlomojohn
    @Shlomojohn3 жыл бұрын

    Really well explained thanks 👍🏻

  • @Owendinga
    @Owendinga7 жыл бұрын

    Super helpful! Thank you!

  • @Akashdoifode
    @Akashdoifode4 жыл бұрын

    Thanks a lot for this video. Really helpful

  • @divyasris9231
    @divyasris92314 жыл бұрын

    super super super. excellent teaching skills.

  • @hamedbakhti1752
    @hamedbakhti17523 жыл бұрын

    Thanks bro!!! its very helpful... Good luck

  • @chaitanyayeturi1312
    @chaitanyayeturi13122 жыл бұрын

    First of all, your teaching style is good, and anyone grabs ur teachings easily, and thanks for teaching us. you are the best tutor I have ever come up with in python language. can u suggest any python language book, which is best to go through other than your channel? Moreover, I am a beginner to python language I thoroughly enjoyed ur videos, if u can suggest me best python book to ur sensibility and I guess it suits me and it helps me to learn further (I like physical like books). In case if u written any books related to this language can u suggest one (or) your favorite book, please......................................

  • @farimankashani8627
    @farimankashani86273 жыл бұрын

    Thank you so much. It was super helpful

  • @dilipwarrier5199
    @dilipwarrier51997 жыл бұрын

    Thank you, Sir. Your videos are extremely helpful.

  • @cooleekova
    @cooleekova2 жыл бұрын

    thank youuu! your tutorials are awesome!

  • @thmmerd
    @thmmerd3 жыл бұрын

    Thank you. This was super cool.

  • @cOnT3ST
    @cOnT3ST4 жыл бұрын

    Great vid! Very useful

  • @NicolasChanCSY
    @NicolasChanCSY3 жыл бұрын

    For anyone who needs to work with paths and don't want to deal with the forward/backward slashes difference between Linux, Windows, and MacOS, you can consider or at least take a look at the module `Pathlib`. It is simpler and easier to manipulate in my opinion. My favourite part of the module is its slash operator, e.g. taken from the documentation ```python >>> p = PurePath('/etc') >>> p PurePosixPath('/etc') >>> p / 'init.d' / 'apache2' PurePosixPath('/etc/init.d/apache2') ``` Thus, you are free from the long `os.path.join()` method call introduced in 14:05 and make things cleaner and more readable.

  • @shazkingdom1702
    @shazkingdom17025 жыл бұрын

    now I understand this OS & good use case for file manipulation! THANK YOU COREY!

  • @opiyosebastian50
    @opiyosebastian506 жыл бұрын

    Thanks for the video, always the best!

  • @dhanasekaranrajendran3773
    @dhanasekaranrajendran37737 жыл бұрын

    Good tutorial... Thanks Corey....

  • @abdallah_eldesouky
    @abdallah_eldesouky2 жыл бұрын

    very informative tutorial, thanks

  • @sibanandanayak2633
    @sibanandanayak26336 жыл бұрын

    gr8 tutorial..looking forward more videos..

  • @rajatpai5048
    @rajatpai50486 жыл бұрын

    Informative and chic tutorial :)

  • @MrKungfu218
    @MrKungfu2184 жыл бұрын

    This was a very good video lesson for me as a beginner. I signed up for a Udemy class but found the content on OS Module functionality left me with some questions. I will definitely be using your videos as a resource1

  • @abeburdock7791

    @abeburdock7791

    4 жыл бұрын

    Which Udemy python class are you taking? I plan on taking a Udemy class for Python to supplement what I learn from Corey's channel. Thanks.

  • @learnpy2583
    @learnpy2583 Жыл бұрын

    this guy is so clear,

  • @umakanths6902
    @umakanths69024 жыл бұрын

    Awesome tutorial Bro......

  • @Wewereneveryoung
    @Wewereneveryoung Жыл бұрын

    THANK YOU for this tutorial

  • @RoamingRebel
    @RoamingRebel4 жыл бұрын

    Its very nice .Thank you

  • @tav9755
    @tav97553 жыл бұрын

    Thanks for this very useful and well presented tut..

  • @ai.simplified..
    @ai.simplified..3 жыл бұрын

    It,s 3rd min &i already loved it.

  • @Imran20091990
    @Imran200919902 жыл бұрын

    Don't know what to say.. excellent 👌👌👌👌

  • @dpynsnyl
    @dpynsnyl4 жыл бұрын

    This is a gold video.

  • @ji-axinliu4448
    @ji-axinliu44483 жыл бұрын

    thank you Sir helped my work a lot

  • @abhisheksharma-ib5vw
    @abhisheksharma-ib5vw6 жыл бұрын

    Incredible info

  • @shrutigupta8818
    @shrutigupta88187 жыл бұрын

    Awesome video sir.

  • @bazarbayhalmedov9722
    @bazarbayhalmedov97227 жыл бұрын

    hey bro thanks for that videos i hope u continue to doing like that

  • @ritheshbcanvas4963
    @ritheshbcanvas49636 жыл бұрын

    U are the best bro..