-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyimg.ps1
52 lines (33 loc) · 2.02 KB
/
copyimg.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
# Create folder "img"
New-Item -ItemType directory -Force -Path C:\Users\m.riedlsperger\Desktop\img
# Copy from "Bildpuffer" and "pdf Puffer" to "img"
Copy-Item -Path 'V:\Bildpuffer\*' -Destination 'C:\Users\m.riedlsperger\Desktop\img'
Copy-Item -Path 'V:\pdf Puffer\*' -Destination 'C:\Users\m.riedlsperger\Desktop\img'
# Copy from "Artikelbilder" and "Sicherheitsdatenblaetter" to "img", if the file is newer than 14 days
Get-ChildItem -Path 'V:\Artikelbilder\' -Recurse|
Where-Object {
$_.LastWriteTime -gt [datetime]::Now.AddDays(-14)
}| Copy-Item -Destination 'C:\Users\m.riedlsperger\Desktop\img'
Get-ChildItem -Path 'V:\Sicherheitsdatenblaetter\' -Recurse|
Where-Object {
$_.LastWriteTime -gt [datetime]::Now.AddDays(-14)
}| Copy-Item -Destination 'C:\Users\m.riedlsperger\Desktop\img'
# Delete evil characters
ls 'C:\Users\m.riedlsperger\Desktop\img' -File -Recurse -Force -EA SilentlyContinue | ?{$_.Basename -match '[^\w\+\-\(\)äöü ]'} | ren -NewName {(Replace-Chars $_.Basename -replaceString '_') + $_.Extension} -Force -Verbose
# Add csv and img folder to zip
Compress-Archive -Path C:\Users\m.riedlsperger\Desktop\catalog.csv -DestinationPath C:\Users\m.riedlsperger\Desktop\catalog.zip
Compress-Archive -Path C:\Users\m.riedlsperger\Desktop\img -Update -DestinationPath C:\Users\m.riedlsperger\Desktop\catalog.zip
# Move zip to ftp-server
Move-Item -Path C:\Users\m.riedlsperger\Desktop\catalog.zip -Destination W:\nordwest\ESHOPIMPORT\catalog.zip -Force
# SRC: https://administrator.de/forum/powershell-regex-unerlaubte-zeichen-und-symbole-aus-dateinamen-entfernen-639712.html
function Replace-Chars([parameter(ValueFromPipeline=$true)]$string,$replaceString='_'){
$r = "[^\w\+\-\(\)äöü ]"
if ($replaceString -match $r){
Write-Error -Message "Parameter '-replaceString' contains invalid filename chars/sequences." -Category InvalidArgument -TargetObject $replaceString
break
}
while($string -match $r){
$string = ($string -replace $r,$replaceString).trim()
}
return $string
}