listing files

listing files

View Answers

April 16, 2009 at 3:45 PM

Hi friend,

Code to help in solving the problem :

import java.io.*;

public class DirListing{
private static void dirlist(String fname){
File dir = new File(fname);
String[] chld = dir.list();
if(chld == null){
System.out.println("Specified directory does not exist or is not a directory.");
System.exit(0);
}else{
for(int i = 0; i < chld.length; i++){
String fileName = chld[i];
System.out.println(fileName);
}
}
}
public static void main(String[] args){
switch(args.length){
case 0: System.out.println("Directory has not mentioned.");
System.exit(0);
case 1: dirlist(args[0]);
System.exit(0);
default : System.out.println("Multiple files are not allow.");
System.exit(0);
}
}
}

Thanks

April 16, 2009 at 3:45 PM

Hi friend,

Code to help in solving the problem :

import java.io.*;

public class DirListing{
private static void dirlist(String fname){
File dir = new File(fname);
String[] chld = dir.list();
if(chld == null){
System.out.println("Specified directory does not exist or is not a directory.");
System.exit(0);
}else{
for(int i = 0; i < chld.length; i++){
String fileName = chld[i];
System.out.println(fileName);
}
}
}
public static void main(String[] args){
switch(args.length){
case 0: System.out.println("Directory has not mentioned.");
System.exit(0);
case 1: dirlist(args[0]);
System.exit(0);
default : System.out.println("Multiple files are not allow.");
System.exit(0);
}
}
}

Thanks









Related Tutorials/Questions & Answers:
listing files - Java Beginners
listing files  how to list the files and number of files only...]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow
PHP listing files in folder
All files, folder   of the given folder can be listed. Function readdir() takes input as the folder handle. Then readdir() returns the name of all the files and folders. Example of PHP Listing Files in Folder
Advertisements
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code:ADS_TO_REPLACE_1 import java.io.*; import
ModuleNotFoundError: No module named 'listing-adorn'
ModuleNotFoundError: No module named 'listing-adorn'  Hi, My... 'listing-adorn' How to remove the ModuleNotFoundError: No module named 'listing-adorn' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_listing'
ModuleNotFoundError: No module named 'pyramid_listing'  Hi, My... named 'pyramid_listing' How to remove the ModuleNotFoundError: No module named 'pyramid_listing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-listing'
ModuleNotFoundError: No module named 'django-listing'  Hi, My... named 'django-listing' How to remove the ModuleNotFoundError: No module named 'django-listing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jmbo-listing'
ModuleNotFoundError: No module named 'jmbo-listing'  Hi, My Python... 'jmbo-listing' How to remove the ModuleNotFoundError: No module named 'jmbo-listing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-ajax-model-listing'
ModuleNotFoundError: No module named 'django-ajax-model-listing'  Hi...: No module named 'django-ajax-model-listing' How to remove the ModuleNotFoundError: No module named 'django-ajax-model-listing' error? Thanks  
ModuleNotFoundError: No module named 'django-ajax-model-listing'
ModuleNotFoundError: No module named 'django-ajax-model-listing'  Hi...: No module named 'django-ajax-model-listing' How to remove the ModuleNotFoundError: No module named 'django-ajax-model-listing' error? Thanks  
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
Listing Contents of a ZIP File
Listing Contents of a ZIP File       Section, provides the way for listing all the elements of a zip file through the java code. Following program helps you for the appropriate
configuration files - Java Beginners
configuration files  i have to use configuration file in my program "listing of number of files and their modified time of directory",but problem is that directory name should be provided through configuratin file not input
Files
files
files
files
files
files
Listing out leap years between certain period
Listing out leap years between certain period  ... the coding for finding and listing out the leap years between two years... will be a leap year. For listing out each year write "+n"
header files
header files   do you have a all header files of java
Uploading files
Uploading files  Hi, Please provide html code for my question. I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
Java Directory - Directory and File Listing Example in Java
Java Directory - Directory and File Listing Example in Java...; This example illustrates how to list files and folders present in the specified... the files and folders present in the directory by calling list() method
How to show only hidden files in Terminal?
How to show only hidden files in Terminal?  Hi, I want to list all the hidden files in a directory. How to show only hidden files in Terminal..., Here is details: -l use a long listing format -d, --directory
How to show only hidden files in Terminal?
How to show only hidden files in Terminal?  Hi, I want to list all the hidden files in a directory. How to show only hidden files in Terminal..., Here is details: -l use a long listing format -d, --directory
How to show only hidden files in Terminal?
How to show only hidden files in Terminal?  Hi, I want to list all the hidden files in a directory. How to show only hidden files in Terminal..., Here is details: -l use a long listing format -d, --directory
configuration files are used in Struts
configuration files are used in Struts  What configuration files are used in Struts
files uploding and downloading codes
files uploding and downloading codes  any one know JSP codes for upload files,download files and delete files from a created virtual memory
invoking exe files on sound
invoking exe files on sound  how to invoke .exe files on input as sound in java
ModuleNotFoundError: No module named 'files'
ModuleNotFoundError: No module named 'files'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'files' How to remove the ModuleNotFoundError: No module named 'files'
download pdf files
download pdf files  pls help me,I don't know how to convert .doc,.docx files into pdf files and download that pdf files using servlet or jsp
php merge files
php merge files  Split and merge files in PHP Classes
replacing regex in large files
replacing regex in large files  replacing regex in large files
get files list - Ajax
get files list  Please,friend how to get files list with directories from ftp server or local files on web browser. Thanks, Tin Linn Soe   Hi friend, Index of Files Index
Retrieving list of uploaded files.
Retrieving list of uploaded files.  I need to retrieve list of files... files on a website. its uploaded. now the file resides in a directory in the server. now the list of uploaded files should be showing in page where other users can
files - Java Beginners
files  Why do we require files to store data?  Hi friend, files to store data, easy to find and access them. Thanks
library files - Development process
library files   Hi members, i am trying to develop a media player in java using netbeans but what library files should i import for this development
merge two war files
merge two war files  How to merge two war files using maven??? is there any command
merge two war files
merge two war files  how to merge two war files using maven
php show list of files
php show list of files  How can i pull the limited number of files in PHP
intersection of two files
intersection of two files  hi!could you please provide me with the java program for displaying intersection of two files
Structs jar files
Structs jar files  please Post required jar files for structs. Thanks, L.Mahesh Kumar
compiling .class files
compiling .class files  how do i compile .class files using eclipse
List files recursively in linux
List files recursively in linux  Hi, How to List files recursively in linux? I want to list all the .php file. Thanks   Hi, You can use following command: find . -name *.php -print Thanks
getting files from VSS
getting files from VSS  I am not able to get the files from VSS.I am using following code. and just let me know is localpath attribute is for our local project path? I am getting the problem in this line failed
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit the form.Send em the answers as soon as possible..   Please visit
encryption and decryption of files
encryption and decryption of files   Please can any one provide me with the code for encryption and decryption of files using RSA algorithm. I want to use a browse option to search for the file which is needed for encryption
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Reading multiple xml files
Reading multiple xml files  How can we read many xml files from a folder? The same procedure as that of "listfiles

Ads