简体   繁体   中英

Replace illegal characters for file operations in linux server in a character string

I have a string name that will generate a file name as paste(name, ".pdf", sep="")

This file will then be moved to another directory after completion.

I would like to proactively avoid any characters in name that might cause errors in file operations like whitespace , \ , [] , other characters like !"§$%&/()= and any others by replacing them. Special characters in German like öäüß should not cause problems and should be allowed.

Since name is a user input I can't know beforehand what a user might input as character which will then cause problems.

Which characters will give me errors?

Is there any solution or regex to do this without explicitly running each character with sub for example df$name<-sub(" ", "_", df$name)

The R package {fs} provides the function fs::path_sanitize() . You probably want to check it out. https://fs.r-lib.org/reference/path_sanitize.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM