简体   繁体   English

从文件路径列表中创建具有不同扩展名的“空”文件

[英]Creating “empty” files with different extensions from list of file paths

I have a list called viszFiles and it has all the file paths to .visz files in a folder ['/Users/Blake/Deskop/blake.shelton.visz', '/Users/Blake/Deskop/bill.bob-1.visz'] . 我有一个名为viszFiles的列表,它在文件夹['/Users/Blake/Deskop/blake.shelton.visz', '/Users/Blake/Deskop/bill.bob-1.visz']中具有.visz文件的所有文件路径['/Users/Blake/Deskop/blake.shelton.visz', '/Users/Blake/Deskop/bill.bob-1.visz']

The list is generated by this snippet of code: 该列表由以下代码片段生成:

viszFiles = [] #List of .visz file paths
for root, dirs, files in os.walk('/Users/Blake/Desktop/'):
    [viszFiles.append(os.path.join('/Users/Blake/Deskop/', _file))
        for _file in files if
            fnmatch.fnmatch(_file, '*.visz')]

I have searched long and hard and have been unsuccessful in finding out how to exactly go about this: Opening the .visz files (which are basically .tar.gz files) and then creating "empty" .ovpn versions of those files keeping just their root name, such as blake.shelton.visz would become blake.shelton.ovpn and so on for any other files with paths in the list. 我经过漫长而艰苦的搜索,未能成功找到解决方法:打开.visz文件(基本上是.tar.gz文件),然后为这些文件创建“空” .ovpn版本,仅保留其根名称(例如blake.shelton.visz)将变为blake.shelton.ovpn,对于列表中具有路径的任何其他文件,依此类推。 I don't want to copy any data, just create a .ovpn (basically a .tar.gz file I believe) "empty" copy with the same root name while maintaining the originals. 我不想复制任何数据,只需创建一个.ovpn(我相信基本上是一个.tar.gz文件)“空”副本,并保留相同的根名称即可。

I'd really appreciate the help! 我非常感谢您的帮助!

If the list of files is being created correctly, you can use some additional lines to create the empty files. 如果正确创建了文件列表,则可以使用其他一些行来创建空文件。 Hope this helps. 希望这可以帮助。

viszFiles = [] #List of .visz file paths
    for root, dirs, files in os.walk('/Users/Blake/Desktop/'):
        [viszFiles.append(os.path.join('/Users/Blake/Deskop/', _file))
            for _file in files if
            fnmatch.fnmatch(_file, '*.visz')]

for file in viszFiles:
    filename, file_extension = os.path.splitext(file)
    filename += '.visz'
    with open(filename,'w') as f:
        pass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM