how can i get the list of all files/folders in a given folder 
Author Message
 how can i get the list of all files/folders in a given folder

hi all ,
can anybody tell me how to get the list of all files/folders in  a given
folder.
I also want to know how to copy a file and paste in another folder
programmatically

pls give me the API or the procedure to do it



Sun, 21 Aug 2005 12:13:11 GMT  
 how can i get the list of all files/folders in a given folder


Quote:
> hi all ,
> can anybody tell me how to get the list of all files/folders in  a given
> folder.
> I also want to know how to copy a file and paste in another folder
> programmatically

> pls give me the API or the procedure to do it

To find all *.TXT files:

Dim strFilename As String

strFilename = Dir$("path_goes_here\*.TXT", vbNormal)
' Gives first filename (note, path not included in name returned).

strFilename = Dir$()
' Gives the next filename, and so must be called repetitively until it
returns "".

By using something like:

strDirname = Dir$("path_goes_here\*", vbDirectory)

you can get a list of folders in the named path instead.

For copying files, I'm not sure if CopyFile is supposed to work in normal
VB - if not, you can simply open the input file, open an output file in
another directory, and read the entire contents writing it out to the output
file as you go.

--
---
Jason Teagle

A list of programming resources I use:
E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
Newsgroups: comp.lang.java.*
Online info & msg boards: www.codeguru.com, www.codeprojects.com
Online info only: www.php.net
---



Sun, 21 Aug 2005 12:33:49 GMT  
 how can i get the list of all files/folders in a given folder


Quote:



> > hi all ,
> > can anybody tell me how to get the list of all files/folders in  a given
> > folder.
> > I also want to know how to copy a file and paste in another folder
> > programmatically

> > pls give me the API or the procedure to do it

> To find all *.TXT files:

My apologies, I thought I was responding in a VB group - duh is me.

Use the FindFirstFile() and FindNextFile() API calls with the
WIN32_FIND_DATA structure to find files, and the CopyFile() API call to copy
files. The principle of files with normal attributes and directory
attributes remains valid though.

--
---
Jason Teagle

A list of programming resources I use:
E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
Newsgroups: comp.lang.java.*
Online info & msg boards: www.codeguru.com, www.codeprojects.com
Online info only: www.php.net
---



Sun, 21 Aug 2005 12:40:44 GMT  
 how can i get the list of all files/folders in a given folder
thanx for the prompt reply ..

but  i will not know the file name or direcotry name .

a directory name will be given .. there will be many files /subfolders in
that folder .
 And in the subfolders there are some files ..with certain characters in the
filenames. Based on those characters .. i have to sort the files into
different folders ..(the folders will be else where )

srinivas


Quote:





> > > hi all ,
> > > can anybody tell me how to get the list of all files/folders in  a
given
> > > folder.
> > > I also want to know how to copy a file and paste in another folder
> > > programmatically

> > > pls give me the API or the procedure to do it

> > To find all *.TXT files:

> My apologies, I thought I was responding in a VB group - duh is me.

> Use the FindFirstFile() and FindNextFile() API calls with the
> WIN32_FIND_DATA structure to find files, and the CopyFile() API call to
copy
> files. The principle of files with normal attributes and directory
> attributes remains valid though.

> --
> ---
> Jason Teagle

> A list of programming resources I use:
> E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
> Newsgroups: comp.lang.java.*
> Online info & msg boards: www.codeguru.com, www.codeprojects.com
> Online info only: www.php.net
> ---



Sun, 21 Aug 2005 13:24:16 GMT  
 how can i get the list of all files/folders in a given folder


Quote:
> thanx for the prompt reply ..

> but  i will not know the file name or direcotry name .

> a directory name will be given .. there will be many files /subfolders in
> that folder .
>  And in the subfolders there are some files ..with certain characters in
the
> filenames. Based on those characters .. i have to sort the files into
> different folders ..(the folders will be else where )

That doesn't seem to be a problem:

(pseudo-code)

void CSomeClass::ListFunnyFiles(CString strRootPath, TCHAR cFunnyChar,
CStringArray& rAryStrFilespecs)
{
    // First, find matching files in the current directory.
    file_pattern = "*" + cFunnyChar + "*.*";
    filspec = strRootPath + "\\" + file_pattern ;
    find_data_struct.attribs = normal ;

    handle = FindFirstFile(filespec, find_data_struct);
    if (handle != INVALID_HANDLE_VALUE)
    {
        bMoreFiles = TRUE ;
        while (bMoreFiles)
        {
            rAryStrFilespecs.Add(strRootPath + find_data_struct.cFilename);
            bMoreFiles = FindNextFile(handle, find_data_struct);
        }
    }

    // Now recurse any subdirectories.
    filspec = strRootPath + "\\*";
    find_data_struct.attribs = directory ;

    handle = FindFirstFile(filespec, find_data_struct);
    if (handle != INVALID_HANDLE_VALUE)
    {
        bMoreDirs = TRUE ;
        while (bMoreDirs)
        {
            if (find_data_struct.cFilename != _T(".")
                && find_data_struct.cFilename != _T("..") )
            {
                // Filename = subdirectory name here.
                ListFunnyFiles(strRootPath + "\\" +
find_data_struct.cFilename, cFunnyChar, rAryStrFilespecs);
                bMoreDirs = FindNextFile(handle, find_data_struct);
            }
        }
    }

Quote:
}

--
---
Jason Teagle

A list of programming resources I use:
E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
Newsgroups: comp.lang.java.*
Online info & msg boards: www.codeguru.com, www.codeprojects.com
Online info only: www.php.net
---



Sun, 21 Aug 2005 13:43:18 GMT  
 how can i get the list of all files/folders in a given folder
1) Use the CFileFind class.
2) Use CopyFile() or SHFileOperation() for this.


Quote:
> hi all ,
> can anybody tell me how to get the list of all files/folders in  a given
> folder.
> I also want to know how to copy a file and paste in another folder
> programmatically

> pls give me the API or the procedure to do it



Sun, 21 Aug 2005 14:49:29 GMT  
 how can i get the list of all files/folders in a given folder
        Take a look at the CFileFind MFC class.
        For file copy process use the CopyFile[Ex]() or the
SHFileOperation() API.

--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------


Quote:
> hi all ,
> can anybody tell me how to get the list of all files/folders in  a given
> folder.
> I also want to know how to copy a file and paste in another folder
> programmatically

> pls give me the API or the procedure to do it



Sun, 21 Aug 2005 16:00:15 GMT  
 how can i get the list of all files/folders in a given folder
thanx everybody
ur suggestions are very useful
srinivas

Quote:



> > thanx for the prompt reply ..

> > but  i will not know the file name or direcotry name .

> > a directory name will be given .. there will be many files /subfolders
in
> > that folder .
> >  And in the subfolders there are some files ..with certain characters in
> the
> > filenames. Based on those characters .. i have to sort the files into
> > different folders ..(the folders will be else where )

> That doesn't seem to be a problem:

> (pseudo-code)

> void CSomeClass::ListFunnyFiles(CString strRootPath, TCHAR cFunnyChar,
> CStringArray& rAryStrFilespecs)
> {
>     // First, find matching files in the current directory.
>     file_pattern = "*" + cFunnyChar + "*.*";
>     filspec = strRootPath + "\\" + file_pattern ;
>     find_data_struct.attribs = normal ;

>     handle = FindFirstFile(filespec, find_data_struct);
>     if (handle != INVALID_HANDLE_VALUE)
>     {
>         bMoreFiles = TRUE ;
>         while (bMoreFiles)
>         {
>             rAryStrFilespecs.Add(strRootPath +

find_data_struct.cFilename);

- Show quoted text -

Quote:
>             bMoreFiles = FindNextFile(handle, find_data_struct);
>         }
>     }

>     // Now recurse any subdirectories.
>     filspec = strRootPath + "\\*";
>     find_data_struct.attribs = directory ;

>     handle = FindFirstFile(filespec, find_data_struct);
>     if (handle != INVALID_HANDLE_VALUE)
>     {
>         bMoreDirs = TRUE ;
>         while (bMoreDirs)
>         {
>             if (find_data_struct.cFilename != _T(".")
>                 && find_data_struct.cFilename != _T("..") )
>             {
>                 // Filename = subdirectory name here.
>                 ListFunnyFiles(strRootPath + "\\" +
> find_data_struct.cFilename, cFunnyChar, rAryStrFilespecs);
>                 bMoreDirs = FindNextFile(handle, find_data_struct);
>             }
>         }
>     }
> }

> --
> ---
> Jason Teagle

> A list of programming resources I use:
> E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
> Newsgroups: comp.lang.java.*
> Online info & msg boards: www.codeguru.com, www.codeprojects.com
> Online info only: www.php.net
> ---



Mon, 22 Aug 2005 05:29:36 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Getting list of files from a folder...WinNT vs Win98

2. Getting a list of files from a folder

3. File/Folder path of a file/folder on the explorer

4. List of accessible folder of a given computer

5. Finding & copying files in folder/sub folders

6. How to find the most recent file in a given folder

7. listing all files in a folder + subfolders

8. File and folders listing functions

9. File list under a folder

10. What class can I use to get a list of files under a specific folder

11. files and folder list

12. Loosing folders in CalssView folder

 

 
Powered by phpBB® Forum Software