OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / test / src_dir / rebol.r
1 ;; =================================================
2 ;; Script: new-suffix.r
3 ;; downloaded from: www.REBOL.org
4 ;; on: 1-Jun-2011
5 ;; at: 21:19:08.38986 UTC
6 ;; owner: carl [script library member who can update
7 ;; this script]
8 ;; =================================================
9 REBOL [
10     Title: "Change File Extensions (Suffix)"
11     File: %new-suffix.r
12     Author: "Carl Sassenrath"
13     Date: 25-Jan-2005
14     Purpose: {
15         Change the file extension (suffix) for files with a specific extension.
16         For example, change all .txt files to .r files in the current directory.
17         Displays a list of changes before it makes them.
18     }
19     Warning: "Back up your files first, just in case!"
20     License: "BSD - Use at your own risk."
21     Library: [
22         level: 'beginner
23         platform: 'all
24         type: [tool]
25         domain: [files]
26         tested-under: none
27         support: none
28         license: 'bsd
29         see-also: none
30     ]
31 ]
32
33 from-suffix: %.txt
34 to-suffix:   %.r
35
36 bulk-rename: func [confirmed] [
37     foreach file load %./ [
38         if all [
39             not find file #"/" ; (ignore directories)
40             from-suffix = find/last file #"."
41         ][
42             new-file: copy file
43             append clear find/last new-file #"." to-suffix
44             either confirmed [
45                 print ["Renaming" file "to" new-file]
46                 rename file new-file
47             ][
48                 print ["Will rename" file "to" new-file]
49             ]
50         ]
51     ]
52 ]
53
54 bulk-rename false
55 if not confirm "Are you sure you want to rename all those files?" [
56     quit
57 ]
58 bulk-rename true
59 ask "Done. Press enter."