forked from nickrod518/PowerShell-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-CAB.ps1
More file actions
executable file
·63 lines (50 loc) · 1.76 KB
/
Copy pathCreate-CAB.ps1
File metadata and controls
executable file
·63 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$project = Read-Host "Folder to convert to a CAB"
$ddf = $project + ".ddf"
$cab = $project + ".cab"
# delete any preexisting ddf
if (Test-Path $ddf) {
Clear-Content $ddf
} else {
$ddf = New-Item -type file $ddf
}
# delete any preexisting cab
if (Test-Path $cab) {
Remove-Item $cab
}
# create the ddf
Add-Content $ddf ".OPTION EXPLICIT"
Add-Content $ddf ".Set CabinetNameTemplate=$cab"
Add-Content $ddf ".Set Cabinet=on"
Add-Content $ddf ".Set Compress=on`n`n"
# add the manifest and any other files in the top most directory of the project
Get-ChildItem $project -File | ForEach-Object {
$trash, $file = $_.FullName -split $project, 2
$file = $project + $file
$file = $([char]34) + $file + $([char]34)
Add-Content $ddf $file
}
# create a new destination directory for each sub directory
Get-ChildItem $project -Directory -Recurse | ForEach-Object {
# if the directory has no files, skip it
if ($_.GetFiles().Count) {
$trash, $folder = $_.FullName -split $project, 2
$folder = $folder.TrimStart('\')
$folder = $([char]34) + $folder + $([char]34)
Add-Content $ddf "`n`n.Set DestinationDir=$folder"
# place the files for each sub directory under its destination directory entry
Get-ChildItem $_.FullName -File | ForEach-Object {
$trash, $file = $_.FullName -split $project, 2
$file = $project + $file
$file = $([char]34) + $file + $([char]34)
Add-Content $ddf $file
}
}
}
# create the cab file
Start-Process MakeCab -ArgumentList "/F ""$ddf""" -Wait
# clean up
Move-Item "disk1\$cab" .
Remove-Item -Force "disk1"
Remove-Item $ddf
Remove-Item ".\setup.inf"
Remove-Item ".\setup.rpt"