Build the full path filename in Python

This works fine: os.path.join(dir_name, base_filename + ‘.’ + filename_suffix) Keep in mind that os.path.join() exists only because different operating systems use different path separator characters. It smooths over that difference so cross-platform code doesn’t have to be cluttered with special cases for each OS. There is no need to do this for file name “extensions” … Read more

Maximum filename length in NTFS (Windows XP and Windows Vista)?

Individual components of a filename (i.e. each subdirectory along the path, and the final filename) are limited to 255 characters, and the total path length is limited to approximately 32,000 characters. However, on Windows, you can’t exceed MAX_PATH value (259 characters for files, 248 for folders). See http://msdn.microsoft.com/en-us/library/aa365247.aspx for full details.

What is the naming standard for path components?

I think your search for a “standard” naming convention will be in vain. Here are my proposals, based on existing, well-known programs: A) C:\users\OddThinking\Documents\My Source\Widget\foo.src — Vim calls it file root (:help filename-modifiers) B) C:\users\OddThinking\Documents\My Source\Widget\foo.src ——- file name or base name C) C:\users\OddThinking\Documents\My Source\Widget\foo.src ___ (without dot) file/name extension D) C:\users\OddThinking\Documents\My Source\Widget\foo.src ____ (with … Read more

Given a filesystem path, is there a shorter way to extract the filename without its extension?

Path.GetFileName Returns the file name and extension of a file path that is represented by a read-only character span. Path.GetFileNameWithoutExtension Returns the file name without the extension of a file path that is represented by a read-only character span. The Path class is wonderful.

Turn a string into a valid filename?

You can look at the Django framework for how they create a “slug” from arbitrary text. A slug is URL- and filename- friendly. The Django text utils define a function, slugify(), that’s probably the gold standard for this kind of thing. Essentially, their code is the following. import unicodedata import re def slugify(value, allow_unicode=False): “”” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)