Base64 Encoding safe for filenames?

Modified Base64 (when /,= and + are replaced) is safe to create names but does not guarantee reverse transformation due to case insensitivity of many file systems and urls. Base64 is case sensitive, so it will not guarantee 1-to-1 mapping in cases of case insensitive file systems (all Windows files systems, ignoring POSIX subsystem cases). … Read more

Open file by filename wildcard

import os import re path = “/home/mypath” for filename in os.listdir(path): if re.match(“text\d+.txt”, filename): with open(os.path.join(path, filename), ‘r’) as f: for line in f: print line, Although you ignored my perfectly fine solution, here you go: import glob path = “/home/mydir/*.txt” for filename in glob.glob(path): with open(filename, ‘r’) as f: for line in f: print … Read more

Get filename from string-path?

Method 1 for %%F in (“C:\Documents and Settings\Usuario\Escritorio\hello\test.txt”) do echo %%~nxF Type HELP FOR for more info. Method 2 call :sub “C:\Documents and Settings\Usuario\Escritorio\hello\test.txt” exit /b :sub echo %~nx1 exit /b Type HELP CALL for more info.

Delete Files with same Prefix String using Java

No, you can’t. Java is rather low-level language — comparing with shell-script — so things like this must be done more explicetly. You should search for files with required mask with folder.listFiles(FilenameFilter), and iterate through returned array deleting each entry. Like this: final File folder = … final File[] files = folder.listFiles( new FilenameFilter() { … Read more

How to make an NSString path (file name) safe

This will remove all invalid characters anywhere in the filename based on Ismail’s invalid character set (I have not verified how complete his set is). – (NSString *)_sanitizeFileNameString:(NSString *)fileName { NSCharacterSet* illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:@”/\\?%*|\”<>”]; return [[fileName componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:@””]; } Credit goes to Peter N Lewis for the idea to use componentsSeparatedByCharactersInSet: NSString – Convert … Read more