Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Pathname: moving files & directories
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Robert Klemme, post: 4681197"] Roughly something like this: # untested require 'pathname' require 'fileutils' require 'set' base = Pathname('/newdir/obsolete') old_dirs = Set.new Pathname.glob('dir/*/obsolete/*').each do |pn| dir, file = pn.split customer = dir.parent.basename target_dir = base + customer target_dir.directoy? or target_dir.mkdir target = target_dir + file FileUtils.mv pn, target old_dirs << dir end old_dirs.each {|d| Dir.delete d} Why can't you experiment at work? You don't need to use real paths or you can omit the final move and delete operations. You need to test your code anyway. Can't you do it on your local machine or a virtual machine? Kind regards robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Pathname: moving files & directories
Top