Touch module in Python

In Python, the Touch module is used to create any file on any specified directory. The touch module is equivalent to linux command ‘touch‘ or to the windows’ cmd command ‘ type null > ‘.

Installation:

This module does not come built-in with Python. To install this module type the below command in the terminal.

pip install touch

Example 1: In this example, we will create a file inside a same directory.

filter_none

edit
close

play_arrow

link
brightness_4
code

import touch
  
touch.touch("success.java")

chevron_right


Output:



python-touch

Example 2: In this example, we will create a file in a different directory. Here we create a file in “testm” folder.

filter_none

edit
close

play_arrow

link
brightness_4
code

import touch
  
touch.touch("testm / success2.java")

chevron_right


Output:

python-touch

Example 3: In this example, we will create a multiple files at the same time. For this, we need to pass the file name in a list.

filter_none

edit
close

play_arrow

link
brightness_4
code

import touch
  
touch.touch(["testm / success100.java", "success10.cpp"])

chevron_right


Output:
python-touch




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.