![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 27104 Articles for Server Side Programming
445 Views
One of the most prevalent activities in modern software development is copying files programmatically. In today's quick tutorial, we'll look at a few different ways to transfer files in Python using the shutil module. Shutil is a Python Standard Library module that provides a wide range of high-level file operations. Now, when it comes to file copying, the library provides a variety of options based on whether you want to copy metadata or file permissions, as well as if the destination is a directory. It falls within the umbrella of Python's basic utility modules. This module aids in the automation ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
882 Views
The shutil module provides functions for copying files, as well as entire folders.Calling shutil.copy(source, destination) will copy the file at the path source to the folder at the path destination. (Both source and destination are strings.) If destination is a filename, it will be used as the new name of the copied file. This function returns a string of the path of the copied file. For example, >>> import shutil >>> # Copy the file in same folder with different name >>> shutil.copy('original.txt', 'duplicate.txt') '/home/username/duplicate.txt' >>> shutil.copy('original.txt', 'my_folder/duplicate.txt') '/home/username/my_folder/duplicate.txt'Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
4K+ Views
In Python, file-handling tasks like opening, reading, writing, and closing files, or manipulating data in files are a common occurrence. While opening files has its significance and utility, it's equally important that files are closed properly to release system resources and to ensure that data integrity is maintained. In this article, we will explore different methods and techniques to close multiple opened files in Python, permitting you to optimize your file-handling operations and maintain clean code. Making Use of a Context Manager In Python, context managers are a tool for efficiently managing resources that need to be properly ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
You can use the os.chroot to change the root directory of the current process to path. This command is only available on Unix systems. You can use it as follows:>>> import os >>> os.chroot('/tmp/my_folder')This changes the root directory of the script running to /tmp/my_folder.
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
607 Views
You can change the owner of a file or a directory using the pwd, grp and os modules. The uid module is used to get the uid from user name, grp to get gid group name string and os to change the owner:Exampleimport pwd import grp import os uid = pwd.getpwnam("my_name").pw_uid gid = grp.getgrnam("my_group").gr_gid path = 'my_folder' os.chown(path, uid, gid)
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
You can change the owner of a file or a directory using the pwd, grp and os modules. The uid module is used to get the uid from user name, grp to get gid group name string and os to change the owner:Exampleimport pwd import grp import os uid = pwd.getpwnam("nobody").pw_uid gid = grp.getgrnam("nogroup").gr_gid path = 'my_folder' os.chown(path, uid, gid)
![Prabhas](https://www.tutorialspoint.com/assets/profiles/13554/profile/60_90506-1512543588.jpg)
14K+ Views
Many of us have a misconception that Java script is an object oriented language. But, the truth is Java Script is an Object Based Language. Object Based languages are different from Object Oriented Languages: Object Based Languages Object based languages supports the usage of object and encapsulation. They does not support inheritance or, polymorphism or, both. Object based languages does not supports built-in objects. Javascript, VB are the examples of object bases languages. Object Oriented Languages Object Oriented Languages supports all the features of Oops including inheritance and polymorphism. They support built-in objects. C#, Java, VB. Net ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
9K+ Views
In Python, concatenation is a process that refers to combining two or more strings, lists, or such sequence-like objects into a single object. The concatenation operation when performed is denoted by using the "+" operator. Concatenating two files into a single file can be a useful process when you want to combine the contents of several files. If you want to merge data from different sources or simply create a consolidated file with aggregated data, Python provides a simple no-frills method to accomplish this task. In this article, we will explore different ways of concatenating two files into a ... Read More
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
12K+ Views
Python makes it simple to create new files, read existing files, append data, or replace data in existing files. With the aid of a few open-source and third-party libraries, it can manage practically all of the file types that are currently supported. We must iterate through all the necessary files, collect their data, and then add it to a new file in order to concatenate several files into a single file. This article demonstrates how to use Python to concatenate multiple files into a single file. Using Loops A list of filenames or file paths to the necessary python files ... Read More
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
779 Views
You might wish to perform a specific action in a Python script only if a file or directory is present or not. For instance, you might wish to read from or write to a configuration file, or only create the file if it doesn't already exist There are many different ways to check if a file exists and figure out what kind of file it is in Python. Using OS Module An inbuilt Python module called Os has tools for dealing with the operating system. We can access operating system features by using os. In Python, os.path is a sub-module ... Read More