Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
f2f534e
1 Parent(s): 48eb7a4

压缩解压换成Powershell实现

Browse files
Files changed (2) hide show
  1. v-corpus-zh/pigz.ps1 +60 -25
  2. v-corpus-zh/pigz_d.ps1 +60 -25
v-corpus-zh/pigz.ps1 CHANGED
@@ -1,25 +1,60 @@
1
- function CompressFiles {
2
- param (
3
- [string]$Path
4
- )
5
-
6
- # ����Ŀ¼
7
- Set-Location -Path $Path
8
-
9
- # ѹ����ǰĿ¼�е����� .txt �ļ�
10
- pigz *.txt
11
-
12
- # ��ȡ��Ŀ¼
13
- $subDirectories = Get-ChildItem -Directory
14
-
15
- # �ݹ���ú�������ÿ����Ŀ¼
16
- foreach ($subDir in $subDirectories) {
17
- CompressFiles -Path $subDir.FullName
18
- }
19
-
20
- # �����ϼ�Ŀ¼
21
- Set-Location -Path ..
22
- }
23
-
24
- # ���ú�����������ʼ·��
25
- CompressFiles -Path (Get-Location).Path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Function Gzip-File([ValidateScript({Test-Path $_})][string]$File){
2
+
3
+ $srcFile = Get-Item -Path $File
4
+ $newFileName = "$($srcFile.FullName).gz"
5
+
6
+ try
7
+ {
8
+ $srcFileStream = New-Object System.IO.FileStream($srcFile.FullName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
9
+ $dstFileStream = New-Object System.IO.FileStream($newFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
10
+ $gzip = New-Object System.IO.Compression.GZipStream($dstFileStream,[System.IO.Compression.CompressionMode]::Compress)
11
+ $srcFileStream.CopyTo($gzip)
12
+ }
13
+ catch
14
+ {
15
+ Write-Host "$_.Exception.Message" -ForegroundColor Red
16
+ }
17
+ finally
18
+ {
19
+ $gzip.Dispose()
20
+ $srcFileStream.Dispose()
21
+ $dstFileStream.Dispose()
22
+ }
23
+ }
24
+
25
+ function CompressFiles {
26
+ param (
27
+ [string]$Path
28
+ )
29
+
30
+ # ����Ŀ¼
31
+ Set-Location -Path $Path
32
+
33
+ # ѹ����ǰĿ¼�е����� .txt �ļ�
34
+ $txtFiles = Get-ChildItem -Path . -Filter *.txt
35
+ # ��������.txt�ļ�
36
+ foreach ($file in $txtFiles) {
37
+ # ��ȡ�ļ�������·��
38
+ $filePath = $file.FullName
39
+
40
+ # ѹ���ļ�
41
+ echo $filePath
42
+ Gzip-File $filePath
43
+ }
44
+
45
+ # ��ȡ��Ŀ¼
46
+ $subDirectories = Get-ChildItem -Directory
47
+
48
+ # �ݹ���ú�������ÿ����Ŀ¼
49
+ foreach ($subDir in $subDirectories) {
50
+ CompressFiles -Path $subDir.FullName
51
+ }
52
+
53
+ # �����ϼ�Ŀ¼
54
+ Set-Location -Path ..
55
+ }
56
+
57
+ # ���ú�����������ʼ·��
58
+ $sPath = (Get-Location).Path
59
+ CompressFiles -Path $sPath
60
+ Set-Location -Path $sPath
v-corpus-zh/pigz_d.ps1 CHANGED
@@ -1,25 +1,60 @@
1
- function CompressFiles {
2
- param (
3
- [string]$Path
4
- )
5
-
6
- # ����Ŀ¼
7
- Set-Location -Path $Path
8
-
9
- # ѹ����ǰĿ¼�е����� .txt �ļ�
10
- pigz -d *.txt.gz
11
-
12
- # ��ȡ��Ŀ¼
13
- $subDirectories = Get-ChildItem -Directory
14
-
15
- # �ݹ���ú�������ÿ����Ŀ¼
16
- foreach ($subDir in $subDirectories) {
17
- CompressFiles -Path $subDir.FullName
18
- }
19
-
20
- # �����ϼ�Ŀ¼
21
- Set-Location -Path ..
22
- }
23
-
24
- # ���ú�����������ʼ·��
25
- CompressFiles -Path (Get-Location).Path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Function Gunzip-File([ValidateScript({Test-Path $_})][string]$File){
2
+
3
+ $srcFile = Get-Item -Path $File
4
+ $newFileName = Join-Path -Path $srcFile.DirectoryName -ChildPath $srcFile.BaseName
5
+
6
+ try
7
+ {
8
+ $srcFileStream = New-Object System.IO.FileStream($srcFile.FullName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
9
+ $dstFileStream = New-Object System.IO.FileStream($newFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
10
+ $gzip = New-Object System.IO.Compression.GZipStream($srcFileStream,[System.IO.Compression.CompressionMode]::Decompress)
11
+ $gzip.CopyTo($dstFileStream)
12
+ }
13
+ catch
14
+ {
15
+ Write-Host "$_.Exception.Message" -ForegroundColor Red
16
+ }
17
+ finally
18
+ {
19
+ $gzip.Dispose()
20
+ $srcFileStream.Dispose()
21
+ $dstFileStream.Dispose()
22
+ }
23
+ }
24
+
25
+ function DecompressFiles {
26
+ param (
27
+ [string]$Path
28
+ )
29
+
30
+ # ����Ŀ¼
31
+ Set-Location -Path $Path
32
+
33
+ # ��ѹ��ǰĿ¼�е����� .txt.gz �ļ�
34
+ $txtFiles = Get-ChildItem -Path . -Filter *.txt.gz
35
+ # ��������.txt.gz�ļ�
36
+ foreach ($file in $txtFiles) {
37
+ # ��ȡ�ļ�������·��
38
+ $filePath = $file.FullName
39
+
40
+ # ��ѹ�ļ�
41
+ echo $filePath
42
+ Gunzip-File $filePath
43
+ }
44
+
45
+ # ��ȡ��Ŀ¼
46
+ $subDirectories = Get-ChildItem -Directory
47
+
48
+ # �ݹ���ú�������ÿ����Ŀ¼
49
+ foreach ($subDir in $subDirectories) {
50
+ DecompressFiles -Path $subDir.FullName
51
+ }
52
+
53
+ # �����ϼ�Ŀ¼
54
+ Set-Location -Path ..
55
+ }
56
+
57
+ # ���ú�����������ʼ·��
58
+ $sPath = (Get-Location).Path
59
+ DecompressFiles -Path $sPath
60
+ Set-Location -Path $sPath