Moving a file from one location to another

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

Moving a file from one location to another

R_Antony
Hi , A simple question, How we can move a file from one location to another ? (i mean cut & paste) Can any one help fast please ? Thanks in advance - Antony
Reply | Threaded
Open this post in threaded view
|

Re: Moving a file from one location to another

Berend Hasselman

On 17-10-2012, at 10:49, Rantony wrote:

> Hi ,A simple question, How we can move a file from one location to another ?
> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>

What does this have to with R?
Will depend on the system you are using.
Look in the help of your file manager.

Berend

>
> --
> View this message in context: http://r.789695.n4.nabble.com/Moving-a-file-from-one-location-to-another-tp4646437.html
> Sent from the R help mailing list archive at Nabble.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: Moving a file from one location to another

Michael Weylandt
On Wed, Oct 17, 2012 at 12:11 PM, Berend Hasselman <[hidden email]> wrote:

>
> On 17-10-2012, at 10:49, Rantony wrote:
>
>> Hi ,A simple question, How we can move a file from one location to another ?
>> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>>
>
> What does this have to with R?
> Will depend on the system you are using.
> Look in the help of your file manager.
>
> Berend

As I have said to "Rantony" multiple times before: this is an OS
operation so you'll likely need to use the system() function to give
your OS the command.

The exact form of the command given depends on your (unstated!) OS but
on Unices its usually some variant on

mv A B

However, I also know that Rantony is on Windows so he'll need a
different command.

To Rantony: please try to improve the quality of your questions. I've
explained multiple times what we look for in a question on this list
and you've really shown very little attempt to improve. At the end of
the day, we are all just volunteers here, so help us help you. You
might even learn something in the process. And please _please_ quote
context if you must post from Nabble.

Michael

______________________________________________
[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: Moving a file from one location to another

Rui Barradas
Hello,

On Windows this should be the old DOS command RENAME (or REN) and
apparently the R function ?file.rename carries it's name.

And yes, the question is terrible. It also shows poor use of the help
system. I didn't know the function name but got it right at the second try:

?file   # no, other stuff
?file.copy  # yes

Hope this helps,

Rui Barradas
Em 17-10-2012 12:27, R. Michael Weylandt escreveu:

> On Wed, Oct 17, 2012 at 12:11 PM, Berend Hasselman <[hidden email]> wrote:
>> On 17-10-2012, at 10:49, Rantony wrote:
>>
>>> Hi ,A simple question, How we can move a file from one location to another ?
>>> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>>>
>> What does this have to with R?
>> Will depend on the system you are using.
>> Look in the help of your file manager.
>>
>> Berend
> As I have said to "Rantony" multiple times before: this is an OS
> operation so you'll likely need to use the system() function to give
> your OS the command.
>
> The exact form of the command given depends on your (unstated!) OS but
> on Unices its usually some variant on
>
> mv A B
>
> However, I also know that Rantony is on Windows so he'll need a
> different command.
>
> To Rantony: please try to improve the quality of your questions. I've
> explained multiple times what we look for in a question on this list
> and you've really shown very little attempt to improve. At the end of
> the day, we are all just volunteers here, so help us help you. You
> might even learn something in the process. And please _please_ quote
> context if you must post from Nabble.
>
> Michael
>
> ______________________________________________
> [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: Moving a file from one location to another

Michael Weylandt
On Wed, Oct 17, 2012 at 12:53 PM, Rui Barradas <[hidden email]> wrote:
> Hello,
>
> On Windows this should be the old DOS command RENAME (or REN) and apparently
> the R function ?file.rename carries it's name.
>

I wasn't aware of the file.*() functions -- I'll of course retract my
statement that this has to be OS direct via system(). Thanks for that
Rui!

Cheers,
Michael

______________________________________________
[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: Moving a file from one location to another

Berend Hasselman
In reply to this post by Rui Barradas

On 17-10-2012, at 13:53, Rui Barradas wrote:

> Hello,
>
> On Windows this should be the old DOS command RENAME (or REN) and apparently the R function ?file.rename carries it's name.
>

If I'm reading the help for file.rename correctly it can't move a file from one directory to another on Windows ("On Windows,file.rename nowadays works across volumes for files but not directories.". If I remember correctly one will have to use system() and the command move.
Assuming that the OP wants to move files from within R (with cut and paste of course)

Berend


> And yes, the question is terrible. It also shows poor use of the help system. I didn't know the function name but got it right at the second try:
>
> ?file   # no, other stuff
> ?file.copy  # yes
>
> Hope this helps,
>
> Rui Barradas
> Em 17-10-2012 12:27, R. Michael Weylandt escreveu:
>> On Wed, Oct 17, 2012 at 12:11 PM, Berend Hasselman <[hidden email]> wrote:
>>> On 17-10-2012, at 10:49, Rantony wrote:
>>>
>>>> Hi ,A simple question, How we can move a file from one location to another ?
>>>> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>>>>
>>> What does this have to with R?
>>> Will depend on the system you are using.
>>> Look in the help of your file manager.
>>>
>>> Berend
>> As I have said to "Rantony" multiple times before: this is an OS
>> operation so you'll likely need to use the system() function to give
>> your OS the command.
>>
>> The exact form of the command given depends on your (unstated!) OS but
>> on Unices its usually some variant on
>>
>> mv A B
>>
>> However, I also know that Rantony is on Windows so he'll need a
>> different command.
>>
>> To Rantony: please try to improve the quality of your questions. I've
>> explained multiple times what we look for in a question on this list
>> and you've really shown very little attempt to improve. At the end of
>> the day, we are all just volunteers here, so help us help you. You
>> might even learn something in the process. And please _please_ quote
>> context if you must post from Nabble.
>>
>> Michael
>>
>> ______________________________________________
>> [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: Moving a file from one location to another

Rui Barradas
Hello,

Inline.
Em 17-10-2012 13:59, Berend Hasselman escreveu:
> On 17-10-2012, at 13:53, Rui Barradas wrote:
>
>> Hello,
>>
>> On Windows this should be the old DOS command RENAME (or REN) and apparently the R function ?file.rename carries it's name.
>>
> If I'm reading the help for file.rename correctly it can't move a file from one directory to another on Windows ("On Windows,file.rename nowadays works across volumes for files but not directories.". If I remember correctly one will have to use system() and the command move.

Or file.copy/file.remove

Rui Barradas

> Assuming that the OP wants to move files from within R (with cut and paste of course)
>
> Berend
>
>
>> And yes, the question is terrible. It also shows poor use of the help system. I didn't know the function name but got it right at the second try:
>>
>> ?file   # no, other stuff
>> ?file.copy  # yes
>>
>> Hope this helps,
>>
>> Rui Barradas
>> Em 17-10-2012 12:27, R. Michael Weylandt escreveu:
>>> On Wed, Oct 17, 2012 at 12:11 PM, Berend Hasselman <[hidden email]> wrote:
>>>> On 17-10-2012, at 10:49, Rantony wrote:
>>>>
>>>>> Hi ,A simple question, How we can move a file from one location to another ?
>>>>> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>>>>>
>>>> What does this have to with R?
>>>> Will depend on the system you are using.
>>>> Look in the help of your file manager.
>>>>
>>>> Berend
>>> As I have said to "Rantony" multiple times before: this is an OS
>>> operation so you'll likely need to use the system() function to give
>>> your OS the command.
>>>
>>> The exact form of the command given depends on your (unstated!) OS but
>>> on Unices its usually some variant on
>>>
>>> mv A B
>>>
>>> However, I also know that Rantony is on Windows so he'll need a
>>> different command.
>>>
>>> To Rantony: please try to improve the quality of your questions. I've
>>> explained multiple times what we look for in a question on this list
>>> and you've really shown very little attempt to improve. At the end of
>>> the day, we are all just volunteers here, so help us help you. You
>>> might even learn something in the process. And please _please_ quote
>>> context if you must post from Nabble.
>>>
>>> Michael
>>>
>>> ______________________________________________
>>> [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: Moving a file from one location to another

Prof Brian Ripley
In reply to this post by Berend Hasselman
On 17/10/2012 13:59, Berend Hasselman wrote:
>
> On 17-10-2012, at 13:53, Rui Barradas wrote:
>
>> Hello,
>>
>> On Windows this should be the old DOS command RENAME (or REN) and apparently the R function ?file.rename carries it's name.
>>
>
> If I'm reading the help for file.rename correctly it can't move a file from one directory to another on Windows ("On Windows,file.rename nowadays works across volumes for files but not directories.". If I remember correctly one will have to use system() and the command move.

You are not.

On Windows, file.rename() can move a normal file from one directory to
another, even to a directory on another volume.

What it cannot do is move a directory from a directory on one file
system (volume in Windows' parlance) to a directory on another.

Basically no program can really move files between file systems, but
some OSes have an atomic copy-and-delete operation and others (including
recent versions of Windows) emulate the move by copying and then
deleting, but not recursively and so only for normal files.

It is hard to write precise documentation where on a POSIX file system a
directory is a file and on a Windows file system it is not.  And you can
have either type of file system on either a POSIX OS or Windows.


> Assuming that the OP wants to move files from within R (with cut and paste of course)
>
> Berend
>
>
>> And yes, the question is terrible. It also shows poor use of the help system. I didn't know the function name but got it right at the second try:
>>
>> ?file   # no, other stuff
>> ?file.copy  # yes
>>
>> Hope this helps,
>>
>> Rui Barradas
>> Em 17-10-2012 12:27, R. Michael Weylandt escreveu:
>>> On Wed, Oct 17, 2012 at 12:11 PM, Berend Hasselman <[hidden email]> wrote:
>>>> On 17-10-2012, at 10:49, Rantony wrote:
>>>>
>>>>> Hi ,A simple question, How we can move a file from one location to another ?
>>>>> (i mean cut & paste)Can any one help fast please ?Thanks in advance- Antony
>>>>>
>>>> What does this have to with R?
>>>> Will depend on the system you are using.
>>>> Look in the help of your file manager.
>>>>
>>>> Berend
>>> As I have said to "Rantony" multiple times before: this is an OS
>>> operation so you'll likely need to use the system() function to give
>>> your OS the command.
>>>
>>> The exact form of the command given depends on your (unstated!) OS but
>>> on Unices its usually some variant on
>>>
>>> mv A B
>>>
>>> However, I also know that Rantony is on Windows so he'll need a
>>> different command.
>>>
>>> To Rantony: please try to improve the quality of your questions. I've
>>> explained multiple times what we look for in a question on this list
>>> and you've really shown very little attempt to improve. At the end of
>>> the day, we are all just volunteers here, so help us help you. You
>>> might even learn something in the process. And please _please_ quote
>>> context if you must post from Nabble.
>>>
>>> Michael
>>>
>>> ______________________________________________
>>> [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.
>


--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[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: Moving a file from one location to another

FJ M
In reply to this post by Michael Weylandt

Thanks for this timely post for me. I'm missing something in cat to get file.rename to work for me. cat puts a NULL at the end of a string. Error: downloading  MSFT .....trying URL 'http://chart.yahoo.com/table.csv?s=MSFT&a=1&b=19&c=2003&d=9&e=17&f=2012&g=d&q=q&y=0&z=MSFT&x=.csv'
Content type 'text/csv' length unknown
opened URL
downloaded 119 Kbdone.
MSFT _Divs.csvNULL
Error in file.rename("Stock_Divs.csv", file_name) : invalid 'to' argument
Execution halted
 Code: library(quantmod)##
## Merge Date OHLC with dividend on ex-dividend date
##
ticker<-c("MSFT","KMI")
Divs_Per_Year<-4for (i in 1:2)
{
Divs<-getDividends(ticker[i])
Stock<-getSymbols.yahoo(ticker[i], from = start(Divs), src = "yahoo", verbose=TRUE, auto.assign=FALSE)
Stock_Divs<-merge(Stock,Divs,fill=0.0)
write.zoo(Stock_Divs, file = "Stock_Divs.csv", append = FALSE, quote = TRUE, sep = ",")
file_name<- cat(ticker[i],"_Divs.csv")
print(file_name)
print
file.rename("Stock_Divs.csv",file_name)
}
Best, FrankChicago
 > From: [hidden email]

> Date: Wed, 17 Oct 2012 13:47:27 +0100
> To: [hidden email]
> CC: [hidden email]; [hidden email]
> Subject: Re: [R] Moving a file from one location to another
>
> On Wed, Oct 17, 2012 at 12:53 PM, Rui Barradas <[hidden email]> wrote:
> > Hello,
> >
> > On Windows this should be the old DOS command RENAME (or REN) and apparently
> > the R function ?file.rename carries it's name.
> >
>
> I wasn't aware of the file.*() functions -- I'll of course retract my
> statement that this has to be OS direct via system(). Thanks for that
> Rui!
>
> Cheers,
> Michael
>
> ______________________________________________
> [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.
     
        [[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: Moving a file from one location to another

Rui Barradas
Hello,

Use paste0(ticker[i], "_Divs.csv")

Rui Barradas
Em 17-10-2012 16:02, FJ M escreveu:

> Thanks for this timely post for me. I'm missing something in cat to get file.rename to work for me. cat puts a NULL at the end of a string. Error: downloading  MSFT .....trying URL 'http://chart.yahoo.com/table.csv?s=MSFT&a=1&b=19&c=2003&d=9&e=17&f=2012&g=d&q=q&y=0&z=MSFT&x=.csv'
> Content type 'text/csv' length unknown
> opened URL
> downloaded 119 Kbdone.
> MSFT _Divs.csvNULL
> Error in file.rename("Stock_Divs.csv", file_name) : invalid 'to' argument
> Execution halted
>   Code: library(quantmod)##
> ## Merge Date OHLC with dividend on ex-dividend date
> ##
> ticker<-c("MSFT","KMI")
> Divs_Per_Year<-4for (i in 1:2)
> {
> Divs<-getDividends(ticker[i])
> Stock<-getSymbols.yahoo(ticker[i], from = start(Divs), src = "yahoo", verbose=TRUE, auto.assign=FALSE)
> Stock_Divs<-merge(Stock,Divs,fill=0.0)
> write.zoo(Stock_Divs, file = "Stock_Divs.csv", append = FALSE, quote = TRUE, sep = ",")
> file_name<- cat(ticker[i],"_Divs.csv")
> print(file_name)
> print
> file.rename("Stock_Divs.csv",file_name)
> }
> Best, FrankChicago
>   > From: [hidden email]
>> Date: Wed, 17 Oct 2012 13:47:27 +0100
>> To: [hidden email]
>> CC: [hidden email]; [hidden email]
>> Subject: Re: [R] Moving a file from one location to another
>>
>> On Wed, Oct 17, 2012 at 12:53 PM, Rui Barradas <[hidden email]> wrote:
>>> Hello,
>>>
>>> On Windows this should be the old DOS command RENAME (or REN) and apparently
>>> the R function ?file.rename carries it's name.
>>>
>> I wasn't aware of the file.*() functions -- I'll of course retract my
>> statement that this has to be OS direct via system(). Thanks for that
>> Rui!
>>
>> Cheers,
>> Michael
>>
>> ______________________________________________
>> [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.