SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    978
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    move and rename file in one function/line, possible?

    so i've been scanning through the ruby docs and i've found
    File.move (deprecated?)
    File.rename
    FileUtils.mv

    is there any way to that i haven't found to do a move and rename at once? Something like
    Code Ruby:
    current_path = blah
    new_path = newBlah
     
    File.move(path_to_file+filename, new_path+new_filename)

    thanks for any help/insight.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You already wrote it. If "to" in File.move is a directory it copies to from to to/from, but if "to" is a filename it does the rename while moving.

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    978
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but is the File.move being forgotten in favor of the FileUtils class?
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  4. #4
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    File is officially deprecated, AFAICT, but that doesn't lose the function because FileUtils.mv should do the exact same thing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •