List all files in a directory, not including the sub directories if any

Hi,
I have been looking around php.net for a bit and can not work
out how i list the files that are in a directory i.e.
www.site.com/directory/
I would like the names of each file to be placed in an array,
but not to have the sub directories in this list should there be
any.
I was given some code a while ago that done this but it
listed the sub directories and i would like them not in this list.
I do not have this code anymore and do not know where i got
it, so i can not get it amended to what i need.
please can someone tell me what line of code i should be
using.
thank you in advance for your help.

(_seb_) wrote:
> not very clever wrote:
>> Hi,
>>
>> I have been looking around php.net for a bit and can
not work out how
>> i list the files that are in a directory i.e.
>>
>> www.site.com/directory/
>>
>> I would like the names of each file to be placed in
an array, but not
>> to have the sub directories in this list should
there be any.
>>
>> I was given some code a while ago that done this but
it listed the
>> sub directories and i would like them not in this
list.
>>
>> I do not have this code anymore and do not know
where i got it, so i
>> can not get it amended to what i need.
>>
>> please can someone tell me what line of code i
should be using.
>>
>> thank you in advance for your help.
>>
>>
>>
>
> The follwoing PHP code will do just that. Just replace
"pathToFolder"
> with the path to your folder.
> I made the list of files also link to each file. Just
remove the link
> echo if you don't them to be links.
>
> <?php
> // FUNCTION TO LIST FILES:
> function listFiles($path){
> if($handle = opendir($path)){
> while(false !== ($file = readdir($handle))){
> if (is_file($path.'/'.$file) &&
!preg_match('/^\./',$file)){
> $files_array[]=$file;
> }
> }
> }
> return($files_array);
> }
> $path = 'pathToFolder';
>
> // CALL THE FUNCTION:
> $files_array = listFiles($path);
> foreach($files_array as $file){
> echo '<p><a
href="'.$path.'/'.$file.'">'.$file,'</a></p>';
> }
>
> ?>
>
I spotted one error:
foreach($files_array as $file){
echo '<p><a
href="'.$path.'/'.$file.'">'.$file,'</a></p>';
should be:
foreach($files_array as $file){
echo '<p><a
href="'.$path.'/'.$file.'">'.$file.'</a></p>';
(a dot after $file, not a coma)
seb ( [email protected])
http://webtrans1.com | high-end web
design
Downloads: Slide Show, Directory Browser, Mailing List

Similar Messages

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • How to modify Exchange 2013 TXT(SMS) notifications to not include the subject line or any of the message body of emails

    We have a group of users who are not permitted to download/save any emails they receive onto public or personal devices, they are only allowed to log in manually and view their mail through OWA (I realize there are ways to use OWA to download mail, however
    the users are explicitly forbidden from doing this, and any countermeasures that can be put in place, are/will be).
    With our new Exchange 2013 server, it seems it has the built in capability to send TXT(SMS) notifications instantly when a user receives mail.  We would like to allow our users to utilize this feature, however currently, the notification includes not
    only the sender of the email, but also the subject line and part of the message body.  As it stands, we can't have this as part of the email would then be saved on their device.
    I am wondering if there is a way to modify Exchange 2013 to not include the subject or message body, so that our users could at least get an instant notification 1-that they have a new email and 2-who it's from?
    Any information would be appreciated, thanks!

    We can configure SMS Text Message Notification for various situation like Calendar notifications, Voice mail notifications, Email notifications if your user's Mailbox hosted in Exchange Server 2013
    To set up your phone to receive text messages when you want to have Calendar notifications, Voice mail notifications, Email notifications use the steps as follows
    Note: Text message fees are applicable and it will appear on your phone bill.
    Login to Outlook Web App, click Options > See All Options > Phone > Voice Mail tab.
         In the Notifications section, choose one of the following options:
    Calendar notifications... 
    Voice mail notifications... 
    Email notifications using an Inbox rule...
    Turn On Notification
    First step is to turn on the notification of text messaging. Click Turn on Notifications
    Select Setup Notification: Need to select your operator,
    It will request to provide your Mobile Operator.
    Note: As of now Exchange Server 2013 supports only the below list of operators.
    Locale: United State
    Mobile Operator: AT & T, Sprint PCS, T-Mobile, Verizon Wireless
    Locale: Canada,
    Mobile Operator:Bell Telus Mobility
    Locale: Romania
    Mobile Operator:Orange Romania
    Provide your telephone number. It will send you the passcode on your mobile number.
    Type the passcode for confirmation
    Calendar Notifications:
    On Selecting Calendar Notification: Select the option based upon your requirement.
    Email Notification Using Inbox Rule:
    Similarly for the text messaging for the email notification, select the option based upon your requirement and setup them up
    Exchange Queries

  • Delete all files in a directory not working for some files

    I have a requirement like wants to delete all the files in a directory. (These files got generated through some other program.)
    Problem is file.delete() is returning false for some of the files..
    (donno the reason .. could be bcoz of file closing issues/locking issues.)
    Looking for a solution where i can delete a file forcefully irrespective of whether the file is opened or not.
    Thanks
    Srini

    are you on windows? if so, it's almost impossible to delete something another process has open.

  • List all files in a directory

    How can I list all the files in a directory which has folders and files as well? I just wanna files..
    File dataDir = new File("c:/data/);
    File[] listing = dataDir.listFiles();
    but it list the immediate no of folders in the data directory. Is there a way to get all the files in the subdirectories in data folder and excluding the folders?
    thanks!

    Iterate over the returned array, ignoring those whose isDirectory() returns true.
    Alternatively, you could call listFiles(fileNameFilter) instead, with an implementation of FileNameFilter which rejects File objects whose isDirectory() returns true.

  • List all files in a directory in order of timestamp

    have files from directory displayed in an array of columns,using the list icon. however i would like them to be in order of aquisition or timestamp, rather then all 1, 10ns 20s etc.
    is there anyway to control the indexing with time stamping order?

    LabVIEW allows you to sort just about anything. All you have to do is create a cluster containing everything you want for a "record" and make an array of those clusters. In your case, you want to cluster the file name with its time stamp (how about last modification date?). The sort function (we call them functions or VIs, not icons) will order your array based on the order in which you clustered your elements.
    I whipped up a tiny example. Give it a directory path and run it. The output is a list of the filed in that folder sorted according to their time stamp.
    If you have some clear specifications for your whole application, consider hiring an Alliance Member (like us). You will end up with a most professional example of LabVIEW code t
    o learn from and tweak as you like.
    Alliance Members are here to help. We do this stuff every day.
    Daniel L. Press
    PrimeTest Corp.
    www.primetest.com
    Attachments:
    List_Files_by_Time.vi ‏21 KB

  • Creating an action that treats all files in a directory

    How can I make an action which changes the picture size and resolution for all files in a directory and saves the new versions of the files in a subdirectory?
    Thanks

    Macro Details wrote:
    First create your Sub directory. Then start the Action. Open file, Resisize save as (to Sub directory) then close the file.
    Now: File- Automate-Batch. Select your action and your folders and overide the open Command and the Save As Command.
    Frankly Norbert I think the Image processor way is easier but to each his own as they say.  

  • How to list all files in a given directory?

    How to list all the files in a given directory?

    A possible recursive algorithm for printing all the files in a directory and its subdirectories is:
    Print the name of the directory
    for each file in the directory:
    if the file is a directory:
    Print its contents recursively
    else
    Print the name of the file.
    Directory "games"
    blackbox
    Directory "CardGames"
    cribbage
    euchre
    tetris
    The Solution
    This program lists the contents of a directory specified by
    the user. The contents of subdirectories are also listed,
    up to any level of nesting. Indentation is used to show
    the level of nesting.
    The user is asked to type in a directory name.
    If the name entered by the user is not a directory, a
    message is printed and the program ends.
    import java.io.*;
    public class RecursiveDirectoryList {
    public static void main(String[] args) {
    String directoryName; // Directory name entered by the user.
    File directory; // File object referring to the directory.
    TextIO.put("Enter a directory name: ");
    directoryName = TextIO.getln().trim();
    directory = new File(directoryName);
    if (directory.isDirectory() == false) {
    // Program needs a directory name. Print an error message.
    if (directory.exists() == false)
    TextIO.putln("There is no such directory!");
    else
    TextIO.putln("That file is not a directory.");
    else {
    // List the contents of directory, with no indentation
    // at the top level.
    listContents( directory, "" );
    } // end main()
    static void listContents(File dir, String indent) {
    // A recursive subroutine that lists the contents of
    // the directory dir, including the contents of its
    // subdirectories to any level of nesting. It is assumed
    // that dir is in fact a directory. The indent parameter
    // is a string of blanks that is prepended to each item in
    // the listing. It grows in length with each increase in
    // the level of directory nesting.
    String[] files; // List of names of files in the directory.
    TextIO.putln(indent + "Directory \"" + dir.getName() + "\":");
    indent += " "; // Increase the indentation for listing the contents.
    files = dir.list();
    for (int i = 0; i < files.length; i++) {
    // If the file is a directory, list its contents
    // recursively. Otherwise, just print its name.
    File f = new File(dir, files);
    if (f.isDirectory())
    listContents(f, indent);
    else
    TextIO.putln(indent + files[i]);
    } // end listContents()
    } // end class RecursiveDirectoryList
    Cheers,
    Kosh!

  • Finder not displaying all files in remote directory

    Sorry, this is a repost as I have gotten no response from my original request here: Finder not displaying all files in remote directory
    I've exported pictures from iPhoto on my iMac to a shared directory on my mac mini. When I access that directory from my iMac, I can see some but not all of the pictures. I know the pictures exported properly because I can see them all from the mac mini. I can open up a terminal window on my iMac and see all of the files; I can also open those files from the terminal.
    I'm running OSX 10.9.4 on both computers, with the mac mini also running OSX Server. I've placed a screen grab below from my iMac of what Finder sees vs what I can see from the terminal.
    Why isn't Finder displaying all of my files?

    thanks for responding
    Adding a new file to the shared folder results in me being able to see the new file from my clients regardless of where it was added from, however the "hidden" files do not suddenly pop up.
    I tried a few more experiments that had interesting results, but still didn't lead me to an answer.
    First I tried copying the files from the remote directory to a local directory; I did this in 2 different ways and had different results. Method A) I copied files from the mounted share to a local dir: "cp /Volumes/MyShare/dir/*.JPG .". Method B) I copied the files using secure copy: "scp user@server:/path/to/dir/*.JPG .".
    Method A resulted in Finder not being able to see the files in the local directory, while Method B did. This was interesting and lead me to suspect an issue with the way I am sharing the directory on the server. From Server settings I have both afp and smb checked. I tried enabling only one or the other and reconnecting; but this did not fix the problem.
    Next I tried exporting the photos from iPhoto again. Exporting them locally results in files that Finder can see. Exporting them to my server results the same bad behavior
    Getting desperate, I also tried renaming all of the files from "*.JPG" to "*.jpg" but this didn't help.
    One last experiment, I see the same behavior from both another Mac and a PC on my local network... FTP works fine.
    Any more ideas?

  • How to list all files and directories in another directory

    I need to be able to list all the directories and files in a directory. I need to write a servlet that allows me to create an html page that has a list of files in that directory and also list all the directories. That list of files will be put into an applet tag as a parameter for an applet that I have already written. I am assuming that reading directories/files recursively on a web server will be the same as reading directories/files on a local system, but I don't know how to do that either.

    Hi,
    Here is a method to rotate through a directory and put all the files into a Vector (files).
          * Iterates throught the files in the root file / directory that is passed
          * as a parameter. The files are loaded into a <code>Vector</code> for
          * processing later.
          * @param file the root directory or the file
          *         that you wish to have inspected.
         public void loadFiles(File file) {
              if (file.isDirectory()) {
                   File[] entry= file.listFiles();
                   for (int i= 0; i < entry.length; i++) {
                        if (entry.isFile()) {
                             //Add the file to the list
                             files.add(entry[i]);
                        } else {
                             if (entry[i].isDirectory()) {
                                  //Iterate over the entries again
                                  loadFiles(entry[i]);
              } else {
                   if (file.isFile()) {
                        //Add the file
                        files.add(file);
    See ya
    Michael

  • EMERGENCY: List of files in Recovery Area not managed by the database

    Hi,
    this is an emergency request....
    I have this data guard set up. And i accidently dropped online redo logs, standby logs and the archive log except the current online redolog.
    i actually ran to cleanup the whole directory which included the controlfile and the datafiles (was on the wrong location on ASM)
    but the controlfile and the datafiles did not get deleted. i can still see them on the ASM.
    and now when i am trying to restore the archive logs, but i keep getting error as shown below...
    WARNING: A file of type ARCHIVED LOG may exist in
    db_recovery_file_dest that is not known to the database.
    Use the RMAN command CATALOG RECOVERY AREA to re-catalog
    any such files. This is most likely the result of a crash
    during file creation.
    so when i did the below i was getting error as:
    RMAN> CATALOG RECOVERY AREA;
    using target database control file instead of recovery catalog
    searching for all files in the recovery area
    no files found to be unknown to the database
    List of files in Recovery Area not managed by the database
    ==========================================================
    File Name: +DATA/afcpdg/controlfile/controlfile01.ctl
    RMAN-07526: Reason: File is not an Oracle Managed File
    File Name: +DATA/afcpdg/onlinelog/group_1.304.718194815
    RMAN-07527: Reason: File was not created using DB_RECOVERY_FILE_DEST initialization parameter
    number of files not managed by recovery area is 82, totaling 168.10GB
    But i do see those data files that RMAN is complaining as shown above in the ASM.
    I HOPE I DID NOT MESS UP THE CONTROLFILE and the DATFILES
    CAN SOMEONE HELP ME FIX THIS MISTAKE THAT I DID.
    Right now the data guard is running fine, the logs are getting shipped from primary and the getting applied at the DG.
    And i am able to see all the redo logs got deleted.
    But not sure how the deleted redo logs got created in the ASM (i did not create them manually)
    Thanks.
    Philip.
    Edited by: user8898644 on May 5, 2010 8:52 AM
    Edited by: user8898644 on May 5, 2010 9:16 AM
    Edited by: user8898644 on May 5, 2010 11:43 AM

    Yes this happened on the standby database.
    I had to restore the archive logs because i deleted all the archive logs which got shipped from the primary.
    I did re-create the standby logs. But when i checked back the redo logs that i deleted came back again.
    I have no idea how they can back again. is it a feature of ASM where a mirrored copy of the files are stored on ASM and they re-create them when accidently dropped.
    Can you help me understand how the redologs got created again automatically.
    Right now the data guard is running fine but i do see the error
    WARNING: A file of type ARCHIVED LOG may exist in
    db_recovery_file_dest that is not known to the database.
    Use the RMAN command CATALOG RECOVERY AREA to re-catalog
    any such files. This is most likely the result of a crash
    during file creation.
    and when i do the following
    RMAN> catalog recovery area;
    i do see errors as below...
    List of files in Recovery Area not managed by the database
    ==========================================================
    File Name: +DATA/afcpdg/controlfile/controlfile01.ctl
    RMAN-07526: Reason: File is not an Oracle Managed File
    File Name: +DATA/afcpdg/onlinelog/group_1.304.718194815
    RMAN-07527: Reason: File was not created using DB_RECOVERY_FILE_DEST initialization parameter
    File Name: +DATA/afcpdg/onlinelog/group_2.372.718194833
    RMAN-07527: Reason: File was not created using DB_RECOVERY_FILE_DEST initialization parameter
    File Name: +DATA/afcpdg/datafile/system.596.715610261
    RMAN-07527: Reason: File was not created using DB_RECOVERY_FILE_DEST initialization parameter
    File Name: +DATA/afcpdg/datafile/undotbs1.571.715603525
    number of files not managed by recovery area is 82, totaling 168.10GB
    we do have the db_create_file_dest and db_recovery_file_dest pointing to the same location as +DATA
    How do i fix the above error?
    Thanks in advance.

  • How to get all files in one directory

    Hi there,
    is there any way to get all the files in one directory?
    e.g. a method
    File[] getAllFiles(String directory){
    Thank you

    Just out of interest, which part of the File API was confusing?
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    If you look down the left-hand side, you'll see a frame listing "All File". If you select "File" from that list, it opens up the API in the right-hand frame. Quite near the top you'll find "listFiles".
    I only ask as this (and other questions easily answered by looking at the API) are frequently asked. Did you overlook it when you read the API or did you just not read it?
    I really want to know. I think there is scope to cater for that behaviour within this site. A nice API finder would be good; something more intelligent than the search function (which people use less frequently even than the API docs).

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Transfer of all files in a directory tree using FTP adapter?

    Hi,
    I'm looking for a solution to transfer a whole directory tree, including the content, from one location to another using the FTP adapter.
    Is there an easy way to accomplish this?
    Any help would be appreciated.
    Thanks
    Sigrid

    Hi Sigrid,
    I'm just wondering on the need to do that using SOA. Is it a regular transfer or one time?
    There's a way to move a single file from one FTP location to another on the same or different FTP server (link to the cases). But in order to move all the files in a directory, you'll have to loop this. The high level steps will be:
    - List all the files recursively that are present in your directory using File List operation
    - Implement the MOVE file operation (or COPY operation) of the FTP Adapter
    - Invoke this MOVE operation in a while loop and pass the file names, as gathered from the File List operation, one by one to MOVE operation
    You can also use single Java Embedding activity and call a Java class that does the File Transfer but depends on your requirements.
    Let us know how you get along.
    Regards,
    Neeraj Sehgal

  • Problem with getting a list of files in a directory

    I'm trying to get a list of files in a particular directory. The problem is I'm also getting a listing of all the sub-directories too. Here is my code:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int i=0;i<filelist.length;i++)
    System.out.println("FileName = " + filelist.getName());
    What am I doing wrong?
    Thanks
    Brad

    You are not doing anything wrong. You just have to test whether a given file is a subdirectory:
    File directory = new File(dir);
    File[] filelist;
    filelist = directory.listFiles();
    for(int n = 0; n < filelist.length; n++) {
      if (!filelist[n].isDirectory())
        System.out.println("FileName = " + filelist[n].getName());
    }S&oslash;ren Bak

Maybe you are looking for