我有一个程序来压缩文件夹中的所有内容.我没有写这个代码,但我发现它在网上某处,我正在使用它.我打算压缩一个文件夹,比如说C:/ folder1/folder2/folder3 /.我想将folder3及其所有内容压缩到一个文件中说folder3.zip.使用下面的代码,一旦我压缩它,folder3.zip的内容将是folder1/folder2/folder3 /和files.我不希望整个路径被压缩,我只想让我感兴趣的子文件夹zip(在这种情况下为folder3).我尝试了一些os.chdir等,但没有运气.
def makeArchive(fileList, archive):
"""
'fileList' is a list of file names - full path each name
'archive' is the file name for the archive with a full path
"""
try:
a = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED)
for f in fileList:
print "archiving file %s" % (f)
a.write(f)
a.close()
return True
except: return False
def dirEntries(dir_name, subdir, *args):
# Creates a list of all files in the folder
'''Return a list of file names found in directory 'dir_name' …Run Code Online (Sandbox Code Playgroud) 我在我创建的文件夹中有一个模块,C:\ PowerShellScripts\Modules.我叫这个mod.psm1.该文件包含两个简单的函数:Write-hello和Write-bye.
现在,我已将此路径(C:\ PowerShellScripts\Modules)添加到我的PSModulePath环境变量路径中.
因此,这应该在我启动PowerShell时自动加载模块.正确?
但是当我运行PowerShell并尝试Write-hello或Write-bye时,它会出错
write-hello:术语'write-hello'不被识别为cmdlet,函数,脚本文件或可操作程序的名称
PSModulePath显示我的路径(C:\ PowerShellScripts \模块),即使$ ENV PowerShell不会加载该文件mod.psm1
我需要再次手动使用Import-Module.可能有什么不对?
我想通过dos将网络接口名称重命名为默认名称,例如“以太网”。
\n\n我知道netsh interface set interface name=\xe2\x80\x9dLocal Area Connection\xe2\x80\x9d newname=\xe2\x80\x9dEthernet\xe2\x80\x9d就是这样做的方法。
我正在运行一个脚本,它不知道接口的名称,对吗?因此,在设置接口的 IP 地址之前,我需要它将其重命名为默认值。
\n\n在不知道接口名称的情况下如何做到这一点?
\n\n有没有办法以某种方式获取接口的名称然后更改它?
\ncmd ×1
ethernet ×1
netsh ×1
networking ×1
powershell ×1
python ×1
subdirectory ×1
windows ×1
zipfile ×1