Command for the current directory Python

Commands for the current directory

Because all use os module

import os

First hit.

--Get the pathname of the current directory

    path = os.getcwd()
    print(path)

--Display folders and files in the current directory

    ls = os.listdir(os.getcwd())
    print(ls)

--Move directory

os.chdir ("Desctop") # This is all you need to move curdir = os.getcwd() print(curdir)

--Get the directory name of the current directory

    curdirname = os.path.basename(os.getcwd())
    print(curdirname)

Recommended Posts

Command for the current directory Python
[Python] Check the current directory, move the directory
How to know the current directory in Python in Blender
Have python read the command output
See python for the first time
What is the python underscore (_) for?
Python Note: Get the current month
Introducing the BOT framework Minette for Python
Start the web server in the current directory
Ask for Pi with the bc command
Learn the design pattern "Command" in Python
Pin current directory to script directory in Python
Python Master RTA for the time being
Launch the Discord Python bot for 24 hours.
MongoDB for the first time in Python
Pandas of the beginner, by the beginner, for the beginner [Python]
Floating point calculation for the awk command
Publish the current directory on the web server
Current directory structure
python [for myself]
Template for creating command line applications in Python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
The fastest way for beginners to master Python
[Python] I tried substituting the function name for the function name
The story of low learning costs for Python
vprof --I tried using the profiler for Python
[Python] matplotlib: Format the diagram for your dissertation
Wagtail is the best CMS for Python! (Perhaps)
Upgrade the Azure Machine Learning SDK for Python
Use logger with Python for the time being
Tips for hitting the ATND API in Python
Python: Prepare a serializer for the class instance:
[Python] I searched for the longest Pokemon Shiritori
Image processing? The story of starting Python for
Archive and compress the entire directory with python
[Python] Predict the appropriate rent for an apartment
Code for checking the operation of Python Matplotlib
Launch an HTTP server in the current directory
Call Polly from the AWS SDK for Python
Unzip all zip files under the current directory
Search for files with line feed code CR + LF under the current directory
See here for the amount of free memory of the free command
Find the maximum Python
Python note: When the pip command cannot be used
[For beginners] How to use say command in python!
Automate background removal for the latest portraits in a directory with Python and API
[Python] File / directory operations
Python basics ② for statement
I tried Python on Mac for the first time.
Directory structure for test-driven development using pytest in python
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
[Python] Measures and displays the time required for processing
[Reintroduction to python] How to import via the parent directory
the zen of Python
I tried python on heroku for the first time
Execute command from Python
About Python, for ~ (range)
python textbook for beginners
Information for controlling the motor with Python on RaspberryPi
sshfs command directory synchronization
Electron is the best solution for Python multi-platform development