Affichage des articles dont le libellé est Directory. Afficher tous les articles
Affichage des articles dont le libellé est Directory. Afficher tous les articles

VB.Net - Check If Folder Contains Files

VB.Net - How To Check If Folder Contains Files Or Folders Using Visual Basic.Net

vb.net check if directory contains files


In This VB.Net Tutorial  We Will See How To Check If A Directory Contains Files Or Other Sub Directory Using Visual Basic.Net Programming Language.


Project Source Code:

Imports System.IO

Public Class Contain_Files_And_Folder

    Private Sub ButtonCheck_Click(sender As Object, e As EventArgs) Handles ButtonCheck.Click

        Dim path As String
        path = TextBox1.Text
        Dim files() As String
        Dim folders() As String

        If Directory.Exists(path) Then

            files = Directory.GetFiles(path)
            folders = Directory.GetDirectories(path)

            Label1.Text = files.Length & " File And " & folders.Length & " Folder "


        End If


    End Sub
End Class

//OutPut:

VB.Net - Check If Folder Contains Files





C# Create File / Folder

How To Create File Or Directory In C#

c# create file and directory


In This C# Tutorial  We Will See How To Create File And Folder In CSharp Programming Language.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form15 : Form
    {
        public Form15()
        {
            InitializeComponent();
        }

       // create file
        private void button1_Click(object sender, EventArgs e)
        {

            string path = textBox1.Text;

            if(!File.Exists(path))
            {
                File.Create(path);
                MessageBox.Show("File Created");
            }
            else
            {
                MessageBox.Show("File Already Exists");
            }

        }

        // create folder
        private void button2_Click(object sender, EventArgs e)
        {
            string path = textBox1.Text;
            if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                MessageBox.Show("Directory Created");
            }
            else
            {
                MessageBox.Show("Directory Already Exists");
            }
        }
    }
}




Java Create File / Folder

How To Create File Or Directory In Java

java create file and folder



In this Java Tutorial we will see How To Create File Or Folder Using Java NetBeans .




Project Source Code:

package javaapplication1;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class Java_Create_File_Or_Directory extends javax.swing.JFrame {

    /**
     * Creates new form Java_Create_File_Or_Directory
     */
    public Java_Create_File_Or_Directory() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTextFieldPath = new javax.swing.JTextField();
        jButtonCreate_File = new javax.swing.JButton();
        jButtonCreate_Directory = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextFieldPath.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTextFieldPath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPathActionPerformed(evt);
            }
        });

        jButtonCreate_File.setText("Create File");
        jButtonCreate_File.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreate_FileActionPerformed(evt);
            }
        });

        jButtonCreate_Directory.setText("Create Directory");
        jButtonCreate_Directory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreate_DirectoryActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jTextFieldPath, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addComponent(jButtonCreate_File, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonCreate_Directory, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(jTextFieldPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCreate_File)
                    .addComponent(jButtonCreate_Directory))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jTextFieldPathActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
    }                                              

    private void jButtonCreate_FileActionPerformed(java.awt.event.ActionEvent evt) {                                                   

        File f = new File(jTextFieldPath.getText());
        if(!f.exists())
        {
            try {
                f.createNewFile();
                f.mkdir();
                JOptionPane.showMessageDialog(null, "File Created");
            } catch (IOException ex) {
                Logger.getLogger(Java_Create_File_Or_Directory.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else{
            JOptionPane.showMessageDialog(null, "File Already Exists");
        }
        
    }                                                  

    private void jButtonCreate_DirectoryActionPerformed(java.awt.event.ActionEvent evt) {                                                        
       
        File directory = new File(jTextFieldPath.getText());
        
        if(!directory.exists())
        {
           directory.mkdir();
           JOptionPane.showMessageDialog(null, "directory Created");
        }
        
        else
        {
         JOptionPane.showMessageDialog(null, "directory Already Exists");
        }
        
    }                                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_Create_File_Or_Directory.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_Create_File_Or_Directory.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_Create_File_Or_Directory.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_Create_File_Or_Directory.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_Create_File_Or_Directory().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButtonCreate_Directory;
    private javax.swing.JButton jButtonCreate_File;
    private javax.swing.JTextField jTextFieldPath;
    // End of variables declaration                   
}






Php Code : How To Show Images From A Folder

Php Code: How To Display Images From A Folder Using Php

________________________________________________________


In this Php Tutorial we will Learn How To Get And Display Only Images From A Directory Using Php .

I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .



 




Php Source Code:

<?php

$dir_path = "folder/";
$extensions_array = array('jpg','png','jpeg');

if(is_dir($dir_path))
{
    $files = scandir($dir_path);
    
    for($i = 0; $i < count($files); $i++)
    {
        if($files[$i] !='.' && $files[$i] !='..')
        {
            // get file name
            echo "File Name -> $files[$i]<br>";
            
            // get file extension
            $file = pathinfo($files[$i]);
            $extension = $file['extension'];
            echo "File Extension-> $extension<br>";
            
           // check file extension
            if(in_array($extension, $extensions_array))
            {
            // show image
            echo "<img src='$dir_path$files[$i]' style='width:100px;height:100px;'><br>";
            }
        }
    }
}





                     
php show image







Php : How To Get Image Size From Directory Using Php

Php Code: How To Show Image Width And Height From A Folder Using Php

________________________________________________________


In this Php Tutorial we will Learn How  To Get And Display Images size ( width & height) From Folder Using Php .

I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .



 




Php Source Code:

<?php

$dir_path = "images/";

if(is_dir($dir_path))
{
    $files = scandir($dir_path);
    
    for($i = 0; $i < count($files); $i++)
    {
        if($files[$i] != '.' && $files[$i] != '..')
        {
            echo "File Name -> $files[$i]<br>";
            
            $imageSize = getimagesize("$dir_path$files[$i]");
            
            echo " -Image Width : $imageSize[0]<br>";

            echo " -Image Height : $imageSize[1]<br>";

            //jpg or png or gif .........
            echo " -Image Type : $imageSize[2]<br>";

            echo " -Image Width And Height: $imageSize[3]<br>";

            // display the images
            echo"<img src='$dir_path$files[$i]' style='width:100px;height:100px;'><br><br>";
        }
    }
}





                     
php display images width and height






Php : How To Get File Extension From Directory Using Php

Php Code: How To Show Files Extension From A Folder Using Php

________________________________________________________


In this Php Tutorial we will Learn How  To Display Files Extensions From Folder Using Php .

I Use In This Tutorial:

- NetBeans IDE .
- XAMPP .



 




Php Source Code:

<?php

$dir_path = "folder/";

if(is_dir($dir_path))
{

    $files = scandir($dir_path);

    for($i = 0; $i < count($files); $i++)
    {

        if($files[$i] !='.' && $files[$i] != '..')
        {

            echo "File Name -> $files[$i]<br>";
            
            $file = pathinfo($files[$i]);

            $extension = $file['extension'];
           
            echo "File Extension -> $extension<br><br>";
        }
    }
}





                     
php files extensions