how to get list of files within a particular local file folder

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get list of files within a particular local file folder

ajayohri
Dear List,

Say I can use getwd() and setwd() to change my working directory. How can I
read in all the files within that directory using command line (like a ls()
but for the path specified)

Regards

Ajay

Websites-
Technology
http://decisionstats.com




On Wed, Jul 4, 2012 at 3:30 PM, <[hidden email]> wrote:

> [hidden email]

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to get list of files within a particular local file folder

ajayohri
Dear List,

Say I can use getwd() and setwd() to change my working directory. How can I
read in all the files within that directory using command line (like a ls()
but for the path specified)

Regards

Ajay

Websites-
Technology
http://decisionstats.com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to get list of files within a particular local file folder

Michael Weylandt
Either dir() or list.files()

Michael

On Jul 4, 2012, at 8:24 AM, Ajay Ohri <[hidden email]> wrote:

> Dear List,
>
> Say I can use getwd() and setwd() to change my working directory. How can I
> read in all the files within that directory using command line (like a ls()
> but for the path specified)
>
> Regards
>
> Ajay
>
> Websites-
> Technology
> http://decisionstats.com
>
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to get list of files within a particular local file folder

Jeff Newmiller
In reply to this post by ajayohri
How you "read all ... files" is up to you, as that depends both on the type of data contained in the files and on how you plan to use the data.

Most likely the solution will involve using the files.list function and either lapply or a for loop, and the data will end up stored in a list of data objects. (If the data are tabular you might use the sapply function to create a single data table.)
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

Ajay Ohri <[hidden email]> wrote:

>Dear List,
>
>Say I can use getwd() and setwd() to change my working directory. How
>can I
>read in all the files within that directory using command line (like a
>ls()
>but for the path specified)
>
>Regards
>
>Ajay
>
>Websites-
>Technology
>http://decisionstats.com
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to get list of files within a particular local file folder

Peter Dalgaard-2
In reply to this post by ajayohri

On Jul 4, 2012, at 15:24 , Ajay Ohri wrote:

> Dear List,
>
> Say I can use getwd() and setwd() to change my working directory. How can I
> read in all the files within that directory using command line (like a ls()
> but for the path specified)

Something like

all <- lapply(list.files(), read.table)

?

-pd

>
> Regards
>
> Ajay
>
> Websites-
> Technology
> http://decisionstats.com
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to get list of files within a particular local file folder

bretschr
In reply to this post by ajayohri
Dear Ajay Ohri,

Re:

> Dear List,
>
> Say I can use getwd() and setwd() to change my working directory. How can I
> read in all the files within that directory using command line (like a ls()
> but for the path specified)
>

I use this function,

#  functions
getFolder <- function(pat)
        {
        txt=file.choose()
        #cat(txt,'\n')
        pos=0
        fname=basename(txt)
        #cat(paste("\nFilename found is: ",fname,'\n'))
        foln = dirname(txt)
        cat(paste("\nFolder name found is: ",foln,'\n'))
        drtext=dir(foln, pattern=pat, full.names = TRUE)
        #cat('\n\n\n\n')
        return(drtext)
        }


Best,

Franklin

Dr F. Bretschneider
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.