Copying a file from one directory to another with Ruby

Something like this should work. my_dir = Dir[“C:/Documents and Settings/user/Desktop/originalfiles/*.doc”] my_dir.each do |filename| name = File.basename(‘filename’, ‘.doc’)[0,4] dest_folder = “C:/Documents and Settings/user/Desktop/destinationfolder/#{name}/” FileUtils.cp(filename, dest_folder) end You have to actually specify the destination folder, I don’t think you can use wildcards.

How to use __dir__?

You can use __DIR__ to get your current script’s directory. It has been in PHP only since version 5.3, and it’s the same as using dirname(__FILE__). In most cases it is used to include another file from an included file. Consider having two files in a directory called inc, which is a subfolder of our … Read more

Is there a way to delete created variables, functions, etc from the memory of the interpreter?

You can delete individual names with del: del x or you can remove them from the globals() object: for name in dir(): if not name.startswith(‘_’): del globals()[name] This is just an example loop; it defensively only deletes names that do not start with an underscore, making a (not unreasoned) assumption that you only used names … Read more

Command to list all files in a folder as well as sub-folders in windows

The below post gives the solution for your scenario. dir /s /b /o:gn /S Displays files in specified directory and all subdirectories. /B Uses bare format (no heading information or summary). /O List by files in sorted order. Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical … Read more