DateTime.ToString() format that can be used in a filename or extension?
You can use this: DateTime.Now.ToString(“yyyy-dd-M–HH-mm-ss”);
You can use this: DateTime.Now.ToString(“yyyy-dd-M–HH-mm-ss”);
I found this larger function in the Chyrp code: /** * Function: sanitize * Returns a sanitized string, typically for URLs. * * Parameters: * $string – The string to sanitize. * $force_lowercase – Force the string to lowercase? * $anal – If set to *true*, will remove all non-alphanumeric characters. */ function sanitize($string, $force_lowercase … Read more
A bit of explaining as to what that %2520 is : The common space character is encoded as %20 as you noted yourself. The % character is encoded as %25. The way you get %2520 is when your url already has a %20 in it, and gets urlencoded again, which transforms the %20 to %2520. … Read more
The answer is that you can’t, unless your filesystem has a bug. Here’s why: There is a system call for renaming your file defined in fs/namei.c called renameat: SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname) When the system call gets invoked, it does a path lookup (do_path_lookup) … Read more
You can just make a System.Uri object, and use IsFile to verify it’s a file, then Uri.LocalPath to extract the filename. This is much safer, as it provides you a means to check the validity of the URI as well. Edit in response to comment: To get just the full filename, I’d use: Uri uri … Read more
var filename = $(‘input[type=file]’).val().split(‘\\’).pop(); or you could just do (because it’s always C:\fakepath that is added for security reasons): var filename = $(‘input[type=file]’).val().replace(/C:\\fakepath\\/i, ”)
Instead of reinventing the wheel, how about using Apache commons-io: import org.apache.commons.io.FilenameUtils; public class FilenameUtilTest { public static void main(String[] args) throws Exception { URL url = new URL(“http://www.example.com/some/path/to/a/file.xml?foo=bar#test”); System.out.println(FilenameUtils.getBaseName(url.getPath())); // -> file System.out.println(FilenameUtils.getExtension(url.getPath())); // -> xml System.out.println(FilenameUtils.getName(url.getPath())); // -> file.xml } }
You should start with the Wikipedia Filename page. It has a decent-sized table (Comparison of filename limitations), listing the reserved characters for quite a lot of file systems. It also has a plethora of other information about each file system, including reserved file names such as CON under MS-DOS. I mention that only because I … Read more
Try os.path.splitext it should do what you want. import os print os.path.splitext(‘/home/user/somefile.txt’)[0]+’.jpg’ # /home/user/somefile.jpg os.path.splitext(‘/home/user/somefile.txt’) # returns (‘/home/user/somefile’, ‘.txt’)
All you have to do is: move the file to two different locations, merge the two commits that do the above, and move one copy back to the original location. You will be able to see historical attributions (using git blame) and full history of changes (using git log) for both files. Suppose you want … Read more