Found 33676 Articles for Programming

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

Sarika Singh
Updated on 15-May-2025 15:26:41

2K+ Views

Listing files and directories using Python is a common task in many applications, from file management tools to automated scripts. However, when we are working on the Windows Operating System, the hidden files and folders are marked using specific file attributes, which can clutter the output if not handled properly. Unlike Unix-based systems, where hidden files typically start with a dot such as .hidden) whereas Windows uses metadata to mark files as hidden. In this article, we'll explore several methods to list only non-hidden files and directories. Basic Filtering by Name Prefix This is the basic Filtering method, which checks ... Read More

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

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

6K+ 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

348 Views

Packages are similar to namespaces in C#.

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

SaiKrishna Tavva
Updated on 01-Sep-2025 14:59:22

6K+ Views

When we are working with directories in Python, a clutter of hidden files can be created. Hidden files are created with a dot (.) on Unix-like operating systems and we can filter them easily. In this article, we will explore different methods to ignore hidden files using the os module and pathlib. Using List Comprehension with os.listdir() In Python, when we use the os.listdir() method the hidden files i.e., the files those are starting with a dot . are also included in the result. To ignore those hidden files and list only visible files we need to pass a condition ... Read More

How to open new pseudo-terminal pair using Python?

Niharikaa Aitam
Updated on 15-May-2025 18:38:47

1K+ Views

Pseudo-terminals (pty) are an advanced and powerful technique in Python when we are dealing with terminal-based processes or simulating interactive sessions programmatically. A pseudo-terminal allows a process to connect to a real terminal. Python provides a built-in pty module that helps in creating and managing these terminal pairs. In this article, we will learn how to open a new pseudo-terminal pair using Python. Using pty.openpty() The pty module in Python provides the openpty() function that returns a tuple containing file descriptors for the master and slave ends of a new pseudo-terminal pair. Example Following is an example, which shows ... Read More

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

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

1K+ 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

Can a constructor be made final in Java?

Aishwarya Naglot
Updated on 29-Jul-2025 16:21:25

7K+ Views

A constructor is a special method in Java that is used to initialize objects. It gets called when an instance of a class is created. The constructor has the same name as the class and does not have a return type. The question is whether a constructor can be declared or made final in Java? The answer is no. Let's understand why. Why can't we declare a Java Constructor "final"? In Java, the final keyword is used to restrict modification of the members of a class (methods and variables). For example, a final method of a class cannot be overridden ... Read More

Is constructor inherited in Java?

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

405 Views

No, constructors are not inherited in Java.

How to create an empty file using Python?

Sarika Singh
Updated on 15-May-2025 18:08:07

24K+ Views

Creating an empty file is a common task in programming when we are initializing log files, setting up placeholders or working with automation scripts. Python provides several easy and flexible methods to create empty files. In this article, we'll go through different ways to create an empty file in Python. Using open() with Write Mode 'w' The open() function is the most straightforward way to create an empty file. When we use the write mode 'w', then it creates a new file if it doesn't exist. Example Following is an example, which shows how to create an empty file using ... Read More

Advertisements