gpt4 book ai didi

python - 如何仅从 splitExt 输出扩展名?

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:41 31 4
gpt4 key购买 nike

我有这个旧的 batch 代码,用于在目录根目录中获取文件(未使用的),并将它们放入目录中(使用文件名作为目录名称):

for %%s in (*.*) do if not "%%~xs"==".!qB" if not "%%~xs"==".parts" (
md "%%~ns" & move "%%s" "%%~ns\"
if exist "%%s" rd "%%~ns"
)

这需要一个 d:\currentdir\filename.ext 文件并使用文件名将其嵌套到 d:\currentdir\filename\filename.ext 中,除非文件扩展名是一个已知的临时文件,如 .!qB.parts

我正在尝试将其重写为 python..

rootfiles = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in rootfiles:
print(os.path.splitext(f))

我被困在 splitExt,如何只获取扩展变量以便排除提到的已知临时扩展?我没有从 documentation 得到它.

最佳答案

试一试:

rootfiles = [f for f in os.listdir('.') if os.path.isfile(f) and not f.endswith(".!qB") and not f.endswith(".parts")]

关于python - 如何仅从 splitExt 输出扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57828215/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com