How to list All files in a directory in Python

If you are working with files and directories in Python, sometimes you ask these question:

  • What is the best way to list all files and directories in Python
  • How can I add all the files in a List in Python
  • How can I add all the directories in a List in Python
  • How to visit all the files in a directory in Python

Here I’ll show some example that answers above questions.

List all files and directories in Python

You can use os.listdir(), if you want to list all the files and directories. This function is very useful and efficient. It will give you everything that is in the directory (including files and directories). This function even includes hidden files and files with only extnsion and no filenames. Here is a syntax to use os.listdir().

... Read More

PHP Code To Send Email Using MySQL Database

There are multiple ways you can send an email to customers retrieved from database. In this article I’ll explain the code that I wrote to bulk send an email to the list of customers retrieved from MySQL database.

PHP script to send an Email

Smallest code you can write to send an email using PHP is below

<?php
   $to = "recipient email";
   $subject = "Subject for the email";
   $body = "Hi test person, This is test email.";
   $header = "From: from@email";
 
   if ( mail($to, $subject, $body, $header)) {
      echo("Success");
   } else {
      echo("Failed");
   }
?>

Now lets extend this code to send the email to list of customers. We will retrieve the list of customers from MySQL databse.

... Read More