Found 34494 Articles for Programming

How to remove swap files using Python?

Sarika Singh
Updated on 17-Aug-2022 14:03:51

555 Views

This Python article will teach you how to recursively remove all files in a folder that have a particular extension. The application will remove all files with the supplied extension inside the folder when we give it the folder path and file extension. Example - using file.endswith() method The steps involved to remove swap files are as follows − Import the _os _module and _listdir _from it. To view a list of all files in a certain folder, use _listdir, and to delete a file, use _os module. The path to the folder containing all files is called folderpath. ... Read More

What are all the ways an object can be created in Java?

varun
Updated on 16-Jun-2020 09:03:59

138 Views

You can create an objectUsing new keyword.Sample obj = new Sample();Using the newInstance() method and Class.forName() method.Sample obj2 = (Sample) Class.forName("Sample").newInstance();Using the clone() method by implementing Cloneable Interface (marker).Sample obj3 = (Sample) obj1.clone();Using class loader.Object obj4 = Sample.class.getClassLoader().loadClass("Sample");Using the constructor class from lang.reflect.Class cls = Sample.class; Constructor obj = cls.getDeclaredConstructors()[0]; Sample obj5 = (Sample) obj.newInstance();

How to remove hidden files and folders using Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 10:13:43

2K+ Views

In the domain of file and folder manipulation, it is found that hidden files and folders can be a source of inconvenience, chaos and confusion, particularly when they are not supposed to be accessible and visible to the end-users. It is a common practice to keep hidden files and folders in a directory that often start with a dot (.) on Unix-based systems (e.g., Linux, macOS) or are designated as hidden on Windows systems. Deleting these hidden files and folders manually can be a tedious task; in this context, Python can be of great help! In this article, we will ... Read More

How to list non-hidden files and directories in windows using Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:18:17

860 Views

When coming across and dealing with file and directory operations within the Windows environment using Python, it's not uncommon to come across the hidden files and directories. These hidden files and folders usually are system files and are purposefully kept out of sight from users. Among these, you might uncover configuration files, those fleeting temporary files, and an array of system−related data. However, in most cases, you may need to list only the non−hidden files and directories to avoid disarray and focus on relevant data. Prepare yourself for a journey through this all−encompassing article. What lies ahead is an exploration ... Read More

How can I list the contents of a directory in Python?

Sarika Singh
Updated on 17-Aug-2022 13:20:42

5K+ Views

A computer's file system's directory is an organisational feature used to store and locate files. A tree of directories is created by organising directories hierarchically. There are parent-child relationships in directories. A folder can also be used to refer to a directory. Python has accumulated a number of APIs that can list the directory contents over time. Useful functions include Path.iterdir, os.scandir, os.walk, Path.rglob, and os.listdir. We could need a list of files or folders in a given directory in Python. You can accomplish this in a number of ways. OS module A function that returns a list of the ... Read More

How to create an object from class in Java?

Prabhas
Updated on 19-Feb-2020 07:39:44

2K+ Views

An object is created from a class using the new keyword. There are three steps when creating an object from a class −Declaration − A variable declaration with a variable name with an object type.Instantiation − The 'new' keyword is used to create the object.Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.Examplepublic class Sample {    public static void main(String args[]){       Sample s = new Sample();    } }

What is the equivalent of C# namespace in Java?

usharani
Updated on 30-Jul-2019 22:30:20

258 Views

Packages are similar to namespaces in C#.

How to ignore hidden files using os.listdir() in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:06:37

4K+ Views

While working with folders or directories in Python, it's a routine experience to encounter hidden files and folders. Hidden files and folders are system files that are not intended to be visible to users, which may include configuration files, temporary files, and system−related data. In many such situations, you may want to ignore these hidden files and only work with the visible ones to avoid clutter and improve the efficiency of your code. In this in−depth article, we will explore different methods to ignore hidden files using the "os.listdir()" function in Python. We will also provide step−by−step explanations and code ... Read More

How to open new pseudo-terminal pair using Python?

Rajendra Dharmkar
Updated on 20-Jul-2023 13:05:33

470 Views

In the realm of Python programming, there arise times and scenarios where we need to interact and work with a terminal environment programmatically. Whether it is required to automate terminal-based tasks or to simulate user input, having the ability and skill to successfully create a new pseudo-terminal pair can be incredibly useful. In this article, we will explore different approaches of how to open a new pseudo-terminal pair using Python and the pty module. So let us get started right away. We have included some code examples with easy-to-follow explanations to guide you through the process. Open a New Pseudo-terminal ... Read More

What is the keyword used in instantiating a class in Java?

seetha
Updated on 30-Jul-2019 22:30:20

937 Views

An object is created from a class. In Java, the new keyword is used to create new objects. There are three steps when creating an object from a class − Declaration − A variable declaration with a variable name with an object type. Instantiation − The 'new' keyword is used to create the object. Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object. Following is an example of creating an object − Example Live Demo public class Puppy { public Puppy(String name) { ... Read More

Advertisements