117 windows
是否可以从命令行中的文件夹创建 .zip 文件,我不想使用任何第三方可执行文件。
我在想诸如“发送到压缩文件夹”之类的事情,但我不知道该怎么做...
Ste*_*nny 101
Windows 10包括 tar.exe:
# example 1
tar.exe -a -c -f out.zip in.txt
# example 2
tar.exe -x -f out.zip
Run Code Online (Sandbox Code Playgroud)
如果您使用的是较旧的 Windows,您仍然可以从libarchive/libarchive下载 。
PowerShell 具有Compress-Archive:
# example 1
Compress-Archive in.txt out.zip
# example 2
Expand-Archive out.zip
Run Code Online (Sandbox Code Playgroud)
对于这两种工具,您都可以使用文件或目录作为输入。
小智 30
想象一下,您想压缩与命令提示符相同的文件夹,而无需打开 powershell 窗口:
powershell Compress-Archive . publish.zip
Run Code Online (Sandbox Code Playgroud)
我结合了来自几个不同来源的这个脚本来更好地满足我的需求。将脚本复制并粘贴到扩展名为“.vbs”的文件中。该脚本最初是为 Windows XP 制作的,但它也适用于 Windows 7 x64 Ultimate - 不能保证 Windows 是否会保留它使用的各种 Shell 对象。
用法:在运行框或命令行中输入-
"C:\zipper.vbs" "C:\folderToZip\" "C:\mynewzip.zip"
Run Code Online (Sandbox Code Playgroud)
脚本路径、源文件夹、要制作的 zip 文件(最后包括 .zip)。
它不会复制空文件夹,所以要小心。
这是vbs代码---
Set Args = Wscript.Arguments
source = Args(0)
target = Args(1)
' make sure source folder has \ at end
If Right(source, 1) <> "\" Then
source = source & "\"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set zip = objFSO.OpenTextFile(target, 2, vbtrue)
' this is the header to designate a file as a zip
zip.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
zip.Close
Set zip = nothing
wscript.sleep 500
Set objApp = CreateObject( "Shell.Application" )
intSkipped = 0
' Loop over items within folder and use CopyHere to put them into the zip folder
For Each objItem in objApp.NameSpace( source ).Items
If objItem.IsFolder Then
Set objFolder = objFSO.GetFolder( objItem.Path )
' if this folder is empty, then skip it as it can't compress empty folders
If objFolder.Files.Count + objFolder.SubFolders.Count = 0 Then
intSkipped = intSkipped + 1
Else
objApp.NameSpace( target ).CopyHere objItem
End If
Else
objApp.NameSpace( target ).CopyHere objItem
End If
Next
intSrcItems = objApp.NameSpace( source ).Items.Count
wscript.sleep 250
' delay until at least items at the top level are available
Do Until objApp.NameSpace( target ).Items.Count + intSkipped = intSrcItems
wscript.sleep 200
Loop
'cleanup
Set objItem = nothing
Set objFolder = nothing
Set objApp = nothing
Set objFSO = nothing
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
461479 次 |
| 最近记录: |