sanitizefilename

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 3 Imported by: 0

README

SanitizeFilename

A handy utility function that will sanitize a given filename string based on the current OS detected by the runtime.

Installation
go get github.com/jacoblockett/sanitizefilename

You can read the godoc here for detailed documentation.

Quickstart
package main

import "github.com/jacoblockett/sanitizefilename"

func main() {
	// Assuming a Windows environment
	filename := "<>:\"/\\|?*abc.txt" // "<>:"/\|?*abc.txt" without escape chars
	sanitized := sanitizefilename.Sanitize(filename)

	fmt.Println(sanitized) // "abc.txt"

	// Assuming a Linux/Unix environment
	filename := "/.."
	sanitized := sanitizefilename.Sanitize(filename)

	fmt.Println(sanitized) // ""
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(filename string) string

Sanitizes the given string under the assumption it represents a filename. Sanitation is OS-agnostic.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL