<commit_before>/*
renamer.go

Renaming files script on various patterns

Author: <NAME> <<EMAIL>> © 2013
*/

package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"regexp"
	"errors"
	"strings"
	"io"
)

var usageMessage string = `
renamer.go (-p <prefix>|-s <suffix>|-i <indexname> -I <num>|-l|-u) [-x <regexp>] [-t <target_dir>] -[cnr]

renamer.go will rename all files matching a regexp or all files in the 
given directory (and optionally in all its subdirectories) by the flag 
chosen. It can add a prefix/suffix, rename according to a 
<name><numeric_index> pattern, make all low/uppercase and copy files 
somewhere else leaving the originals untouched.

Arguments:

	-prefix|-p <prefix>
		Renames matching files by adding a prefix

	-suffix|-s <suffix>
		Renames matching files by adding a suffix

	-index|-i <name>
		Renames matching files to <name><num>. Requires '-I'

	-startnumber|-I <num>
		The <num> to start renaming in index mode. Requires '-i'

	-regexp|-x <regexp>
		The regular expression for matching files. Use double quotes 
		around it

	-target-dir|-t <path>
		The directory where to rename/copy the files. Default is the 
		current directory

	-copy|-c
		Copy instead of renaming

	-lowercase|-l
		Lowercase the new filename. It is mutually exclusive with 
		'-u'

	-uppercase|-u
		Uppercase the new filename. It is mutually exclusive with 
		'-l'

	-dry-run|-n
		List files but don't actually perform any action

	-force|-f
		Overwrite existing files. The default is to not copy/rename 
		if the target file already exists

	-recursive|-r
		Operate recursively on all subdirectories of target-dir
`

var regexpArg string // the regexp argument
var fileRegex *regexp.Regexp // the files matching the regexp
var prefixArg string // the prefix
var suffixArg string // the suffix
var indexArg string  // the <name> in the <name><num> pattern
var numArg int // the <num> in the <name><num> pattern
var targetArg string // the target directory
var lowerArg bool // the lowercase switch
var upperArg bool // the uppercase switch
var copyArg bool // the copy switch
var dryrunArg bool // the dry-run switch
var forceArg bool  // the force switch
var recursiveArg bool // the recursive switch

var operationSuccessful int // numeric flag to keep trace of what went 
			// wrong during the renaming

// Print a message and the usage instructions
func printUsage(msg string) {
	fmt.Fprintf(os.Stderr, msg + "\n")
	fmt.Fprintf(os.Stderr, usageMessage)
	os.Exit(2)
}

// Parse flags ("arguments")
func flagsInit() {
	// Use our custom usageMessage to print usage instructions
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, usageMessage)
	}

	const (
		def_regexp		= ""
		def_prefix		= ""
		def_suffix		= ""
		def_index		= ""
		def_num			= 1
		def_target		= ""
		def_lowercase	= false
		def_uppercase	= false
		def_copy		= false
		def_dryrun		= false
		def_force		= false
		def_recursive	= false
	)

	flag.StringVar(&regexpArg, "regexp", def_regexp, "")
	flag.StringVar(&regexpArg, "x", def_regexp, "")
	flag.StringVar(&prefixArg, "prefix", def_prefix, "")
	flag.StringVar(&prefixArg, "p", def_prefix, "")
	flag.StringVar(&suffixArg, "suffix", def_suffix, "")<commit_msg>Set def_target to "." so to match the current directory by default<commit_after>/*
renamer.go

Renaming files script on various patterns

Author: <NAME> <<EMAIL>> © 2013
*/

package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"regexp"
	"errors"
	"strings"
	"io"
)

var usageMessage string = `
renamer.go (-p <prefix>|-s <suffix>|-i <indexname> -I <num>|-l|-u) [-x <regexp>] [-t <target_dir>] -[cnr]

renamer.go will rename all files matching a regexp or all files in the 
given directory (and optionally in all its subdirectories) by the flag 
chosen. It can add a prefix/suffix, rename according to a 
<name><numeric_index> pattern, make all low/uppercase and copy files 
somewhere else leaving the originals untouched.

Arguments:

	-prefix|-p <prefix>
		Renames matching files by adding a prefix

	-suffix|-s <suffix>
		Renames matching files by adding a suffix

	-index|-i <name>
		Renames matching files to <name><num>. Requires '-I'

	-startnumber|-I <num>
		The <num> to start renaming in index mode. Requires '-i'

	-regexp|-x <regexp>
		The regular expression for matching files. Use double quotes 
		around it

	-target-dir|-t <path>
		The directory where to rename/copy the files. Default is the 
		current directory

	-copy|-c
		Copy instead of renaming

	-lowercase|-l
		Lowercase the new filename. It is mutually exclusive with 
		'-u'

	-uppercase|-u
		Uppercase the new filename. It is mutually exclusive with 
		'-l'

	-dry-run|-n
		List files but don't actually perform any action

	-force|-f
		Overwrite existing files. The default is to not copy/rename 
		if the target file already exists

	-recursive|-r
		Operate recursively on all subdirectories of target-dir
`

var regexpArg string // the regexp argument
var fileRegex *regexp.Regexp // the files matching the regexp
var prefixArg string // the prefix
var suffixArg string // the suffix
var indexArg string  // the <name> in the <name><num> pattern
var numArg int // the <num> in the <name><num> pattern
var targetArg string // the target directory
var lowerArg bool // the lowercase switch
var upperArg bool // the uppercase switch
var copyArg bool // the copy switch
var dryrunArg bool // the dry-run switch
var forceArg bool  // the force switch
var recursiveArg bool // the recursive switch

var operationSuccessful int // numeric flag to keep trace of what went 
			// wrong during the renaming

// Print a message and the usage instructions
func printUsage(msg string) {
	fmt.Fprintf(os.Stderr, msg + "\n")
	fmt.Fprintf(os.Stderr, usageMessage)
	os.Exit(2)
}

// Parse flags ("arguments")
func flagsInit() {
	// Use our custom usageMessage to print usage instructions
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, usageMessage)
	}

	const (
		def_regexp		= ""
		def_prefix		= ""
		def_suffix		= ""
		def_index		= ""
		def_num			= 1
		def_target		= "."
		def_lowercase	= false
		def_uppercase	= false
		def_copy		= false
		def_dryrun		= false
		def_force		= false
		def_recursive	= false
	)

	flag.StringVar(&regexpArg, "regexp", def_regexp, "")
	flag.StringVar(&regexpArg, "x", def_regexp, "")
	flag.StringVar(&prefixArg, "prefix", def_prefix, "")
	flag.StringVar(&prefixArg, "p", def_prefix, "")
	flag.StringVar(&suffixArg, "suffix", def_suffix, "")
{'fraction_non_alphanumeric': 0.10444513521914828, 'fraction_numerical': 0.0018650917003419335, 'mean_word_length': 3.622844827586207, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1936407', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2065, 'n_words': 772}