-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-dirs.ps1
61 lines (56 loc) · 1.9 KB
/
create-dirs.ps1
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
function testDirExists($dir_path, $dir_name, $arg_count) {
if ((test-path -Path $dir_path) -eq $false) {
Write-Error "'$dir_name' directory not found by the path: $dir_path`nEither place '$dir_name' directory in directory with this script or specify full path as $arg_count script argument."
return $false
}
return $true
}
$sript_path = $PSCommandPath | Split-Path -Parent
#get .idea dir
if ($args.Length -gt 1) {
$dot_idea_dir = $args[1]
}
else {
$dot_idea_dir = $sript_path
}
if ((testDirExists $dot_idea_dir ".idea" 2) -eq $false) {
exit -1
}
#get directory with .iml files
if ($args.Length -gt 0) {
$imls_dir = $args[0]
}
else {
$imls_dir = Join-Path $sript_path "imls"
}
testDirExists $imls_dir 'iml' 1
Write-Output "Scipt location: $sript_path"
Write-Output ".idea dir location: $dot_idea_dir"
Write-Output "iml files location: $imls_dir"
Write-Output ""
foreach ($line in Get-Content "$dot_idea_dir\.idea\modules.xml") {
if ( [regex]::IsMatch($line, "^\s*<module fileurl")) {
Write-Output ""
$start = $line.IndexOf('filepath="$PROJECT_DIR$')
$filepath = $line.Substring($start)
Write-Output "Processing file: $filepath"
$dir_matches = ([regex]'/(\w|/|\.|\-)+/').Matches($filepath);
$file_matches = ([regex]'(\w|\-|\.)+\.iml').Matches($filepath);
$path = $dir_matches[0]
$file_name = $file_matches[0]
Write-Output "Dir name: $path"
Write-Output "File name: $file_name"
$full_path = Join-Path $dot_idea_dir $path
if (!(test-path $full_path)) {
Write-Output "Creating dir: $full_path"
New-Item -path $full_path -type directory #-Force
}
else {
Write-Output "Directory: '$full_path' already exists"
}
$iml_file_src = Join-Path $imls_dir $file_name
$iml_file_dst = Join-Path $full_path $file_name
Write-Output "Copy file from $iml_file_src to $iml_file_dst"
Copy-Item -Path $iml_file_src -Destination $iml_file_dst
}
}