This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fuss:ruby [2015/01/09 05:34] – external edit 127.0.0.1 | fuss:ruby [2025/10/21 23:26] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| <code ruby> | <code ruby> | ||
| - | ########################################################## | + | ################# |
| - | ## Wizardry and Steamworks | + | ## |
| - | ########################################################## | + | ################# |
| def wasListReverse(list = []) | def wasListReverse(list = []) | ||
| if list.length <= 1; return list; end | if list.length <= 1; return list; end | ||
| Line 15: | Line 15: | ||
| <code ruby> | <code ruby> | ||
| - | ########################################################## | + | ################# |
| - | ## Wizardry and Steamworks | + | ## |
| - | ########################################################## | + | ################# |
| def wasDualQuicksort(a = [], b = []) | def wasDualQuicksort(a = [], b = []) | ||
| raise(" | raise(" | ||
| Line 80: | Line 80: | ||
| <code ruby> | <code ruby> | ||
| - | ########################################################## | + | ################# |
| - | ## Wizardry and Steamworks | + | ## |
| - | ########################################################## | + | ################# |
| def wasListStride(list=[], | def wasListStride(list=[], | ||
| if start > 0 | if start > 0 | ||
| Line 99: | Line 99: | ||
| </ | </ | ||
| + | ====== Sort Files Into Directories ====== | ||
| + | The following program is meant to run in a directory containing unsorted files. The script creates directories '' | ||
| + | |||
| + | <code ruby> | ||
| + | # | ||
| + | ########################################################################### | ||
| + | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## | ||
| + | ########################################################################### | ||
| + | # Get all the files in the current directory. | ||
| + | entries = Dir.entries( | ||
| + | Dir.pwd | ||
| + | ).select( | ||
| + | & | ||
| + | |x| | ||
| + | !File.directory? | ||
| + | File.basename("# | ||
| + | } | ||
| + | ) | ||
| + | # Sort files in [0-9A-Z] directories. | ||
| + | (" | ||
| + | begin | ||
| + | if !Dir.exists? | ||
| + | Dir.mkdir(dir) | ||
| + | end | ||
| + | entries.select(& | ||
| + | File.rename(file, | ||
| + | end | ||
| + | rescue | ||
| + | puts "Could not move files to: " + dir | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | An example application is a directory containing a bunch of archives which you want to sort into directories from '' | ||
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.