Skip to content

脚本无法使用,可以参考以下方式修改 #3

@gaojingwen945

Description

@gaojingwen945

使用原脚本时,总是提示目标文件夹中的某文件不存在,应该是source设置为了toFullName导致的。
可以改写为读写文件的方式,测试ok。
附参考链接:http://blog.csdn.net/jy692405180/article/details/52409369
修改后的脚本如下:

for root, dirs, files in os.walk(fromFilePath):
    for name in files:
	fileName, fileSuffix = os.path.splitext(name)
	if fileSuffix == '.png' or fileSuffix == '.jpg':
		toFullPath = toFilePath + root[len(fromFilePath):]
		toFullName = toFullPath + '/' + name
		fromFullPath = fromFilePath + root[len(fromFilePath):]
		fromFullName = fromFullPath + '/' + name

		if os.path.isdir(toFullPath):
			pass
		else:
			os.mkdir(toFullPath)
		
		source = tinify.from_file(fromFullName)
		source.to_file(toFullName)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions