filenames

How to read filenames in a folder and access them in an alphabetical and increasing number order?

馋奶兔 提交于 2021-02-16 14:49:09
问题 I would like to ask how to efficiently handle accessing of filenames in a folder in the right order (alphabetical and increasing in number). For example, I have the following files in a folder: apple1.dat, apple2.dat, apple10.dat, banana1.dat, banana2.dat, banana10.dat. I would like to read the contents of the files such that apple1.dat will be read first and banana10.dat will be read last. Thanks. This is what I did so far. from glob import glob files=glob('*.dat') for list in files # I read

File name with prefix and number

社会主义新天地 提交于 2021-02-11 15:10:22
问题 i have this problem, I want create this filename of xml file: NOHEL+number.xml The number is from variable number, where i added +1 always when i send file out. NOHEL is prefix. Exapmle: NOHEL1.xml NOHEL2.xml NOHEL3.xml And i want give there... string strFileName = @"C:\\Users\\L\\Desktop\\NOHEL+number.xml"; Have you any ideas? 回答1: Try this: string strFileName = @"C:\Users\L\Desktop\NOHEL" + number + ".xml"; By the way, you don't need to escape characters with \ when you have @ . 回答2: You

File name with prefix and number

回眸只為那壹抹淺笑 提交于 2021-02-11 15:06:08
问题 i have this problem, I want create this filename of xml file: NOHEL+number.xml The number is from variable number, where i added +1 always when i send file out. NOHEL is prefix. Exapmle: NOHEL1.xml NOHEL2.xml NOHEL3.xml And i want give there... string strFileName = @"C:\\Users\\L\\Desktop\\NOHEL+number.xml"; Have you any ideas? 回答1: Try this: string strFileName = @"C:\Users\L\Desktop\NOHEL" + number + ".xml"; By the way, you don't need to escape characters with \ when you have @ . 回答2: You

Automatically open files given as command line arguments in Python

自古美人都是妖i 提交于 2021-02-11 10:54:10
问题 I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input. while ( <> ) { print $_; } Is there a way to do something similar in Python without having to explicitly open each file? 回答1: The fileinput module in Python's standard library is designed exactly for this purpose, and I quote

Dash download in-memory generated file on button click: How to give filename?

回眸只為那壹抹淺笑 提交于 2021-02-10 18:21:46
问题 I generate an in-memory Excel file via pd.ExcelWriter and BytesIO for a click event in my Python3.8 dash app. Everything works as it should be. When I download my file I get this popup message asking me if I would like to continue to download/open the generated file. However, the popup message shows this (I guess base64 encoded) string (or path?), e.g. ...ydaHdjhgk328AAAAnxsAA== and after downloading the download gets a (randomly assigned?) set of characters as the filename (e.g. ZySzsdn1

Command to truncate all filenames at 255 characters

限于喜欢 提交于 2021-02-08 11:11:43
问题 An NTFS directory is open in a bash shell. what command will recursively truncate all filenames in a directory to the 255 character limit required for ext3? 回答1: If you have access to a Windows shell, you can use: @echo off setlocal EnableDelayedExpansion REM loop over all files in the cwd for /f %%a in ('dir /a-d /b') do ( REM store this filename in a variable so we can do substringing set ThisFileName=%%a REM now take a substring set ThisShortFileName=!ThisFileName:~0,255! REM finally, the

Command to truncate all filenames at 255 characters

寵の児 提交于 2021-02-08 11:09:28
问题 An NTFS directory is open in a bash shell. what command will recursively truncate all filenames in a directory to the 255 character limit required for ext3? 回答1: If you have access to a Windows shell, you can use: @echo off setlocal EnableDelayedExpansion REM loop over all files in the cwd for /f %%a in ('dir /a-d /b') do ( REM store this filename in a variable so we can do substringing set ThisFileName=%%a REM now take a substring set ThisShortFileName=!ThisFileName:~0,255! REM finally, the

Python3 list files from particular directory [duplicate]

不想你离开。 提交于 2021-02-07 11:16:43
问题 This question already has answers here : How do I list all files of a directory? (21 answers) Non-recursive os.walk() (4 answers) Directory-tree listing in Python (20 answers) Closed 4 years ago . How to list file names which are only from a particular directory? I don't want file names from sub-directory or anything. 回答1: os.listdir(dir) Also see List files in ONLY the current directory 来源: https://stackoverflow.com/questions/37489280/python3-list-files-from-particular-directory

Python3 list files from particular directory [duplicate]

♀尐吖头ヾ 提交于 2021-02-07 11:15:23
问题 This question already has answers here : How do I list all files of a directory? (21 answers) Non-recursive os.walk() (4 answers) Directory-tree listing in Python (20 answers) Closed 4 years ago . How to list file names which are only from a particular directory? I don't want file names from sub-directory or anything. 回答1: os.listdir(dir) Also see List files in ONLY the current directory 来源: https://stackoverflow.com/questions/37489280/python3-list-files-from-particular-directory

How can I validate if a file is name valid in Windows?

余生颓废 提交于 2021-02-07 05:39:23
问题 Is there a Windows API function that I can pass a string value to that will return a value indicating whether a file name is valid or not? I need to verify that a file name is valid, and I'm looking for an easy way to do it without re-inventing the wheel. I'm working in straight C, but targeting the Win32 API. If there's no such function built-in, how would I go about writing my own? Is there a general algorithm or pattern that Windows follows for determining file name validity? 回答1: The