How can I create files on Windows with embedded slash using Python?

After an hour and a half Google search, I am surprised that I can not find a way to create a file in Windows with slashes in the name. The client requires that the file names have the following structure:

04/28/2012 04:07 PM 6.781 12Q1_C125_G_04-17.pdf

So far, I have not found a way to encode slashes so that they become part of the file name instead of the path.

Any suggestions?

+4
source share
3 answers

You can not.

A slash is one of the characters that are not allowed for use in Windows file names, see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

The following basic rules allow applications to create and process valid names for files and directories, regardless of the file system:

Use a period to separate the base file name from the extension in the directory or file name.

Use backslash ( \ ) to separate path components. The backslash divides the file name from the path to it and one directory name from another directory name in the path. You cannot use a backslash in a name for an actual file or directory, because it is a reserved character that separates the names into components.

Use the backslash as required as part of the volume names, for example, "C: \" in "C: \ path \ file" or "\ server \ share" in "\ server \ share \ path \ file" for universal convention about names (UNC) names. For more information about UNC names, see Maximum Path Length Limit.

Do not include case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same, although some file systems (such as the POSIX-compatible file system) may treat them differently. Note that NTFS supports POSIX semantics for case sensitivity, but this is not the default behavior. For more information, see CreateFile.

Volume designations (letter letters) are also case insensitive. For example, "D: \" and "d: \" refer to the same thing.

Use any character on the current code page for the name, including Unicode characters and characters in the extended character set (128-255), except for the following:

  The following reserved characters: < (less than) > (greater than) : (colon) " (double quote) / (forward slash) \ (backslash) | (vertical bar or pipe) ? (question mark) * (asterisk) 

The integer value is zero, sometimes called the NULL ASCII character.

Characters whose integer representations range from 1 to 31, with the exception of alternative data streams where these characters are allowed. For more information about file streams, see the File section. Streams.

Any other character that the target file system does not allow.

+11
source

At least all the Windows installations I've seen will not allow you to create slash files. Even if it were possible to do deep magic, it would probably ruin almost all applications, including Windows Explorer.

you can use the unicode features for windows.

Creating a file with (this is not a slash, it is a "slash division", see http://www.fileformat.info/info/unicode/char/2215/index.htm ) in this name works just fine, for example.

+6
source

Um ... a forward slash is not a legal character in a Windows file name?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

-1
source

Source: https://habr.com/ru/post/1413824/


All Articles