Yakın zamanda yapılan bir forum içi sohbette şöyle bir ifade geçmişti (@burak35) :
Bende buna göre bir betik açık algoritması oluşturdum. (Sözel Akış Diyagramı) :Gpediti yönetici hakkıyla çalıştıran bir vbscriptim vardı. Teeee geçen sene yazmışım. onunla çalıştırıp baktım.
bu powershell ayarları bende varmış. ve hiçbirine dokunmamışım. gösterdiğin iyi oldu. teşekkürler.
ama powershell için uğraşmaya çok fazla değmezmiş. onu anladım. son 2 3 gündür sabahlara kadar uğraştım.
bi iş için bi script lazım oldu. chatgptye girdim. dedimki elimde bir dosya var. içinde çok fazla satır var.
script bunu kontrol etsin. içinde gereksiz hatalı yanlış ne varsa bana göstersin. sonrada ben onay verince silsin.
sonra bana bikaç taslak verdi. sonra yok şuda olsun mu buda olsun mu derken baya bildiğin programa benzeyen birşeye dönüştürdü.
epey bi kullandım. ama yok. olacak gibi değil. bi menüye girersin sonuç göstermez. başka menüye girersin kapanır.
çok çok uğraştım. hemde sabahlara kadar. ama olmadı. bende dayanamadım. komple silip attım.
kodları veren kendisi. sürekli hata yapan yine kendisi. verdiği adımları yapıyorum. tam bi yeri düzeltiyoruz.
hop bambaşka bi yerden bambaşka bi hata veriyo. kimi syntax hatası. kimi hesap hatası. uğraş dur.
bende dayanamadım. vazgeçtim. ha bana ne faydası oldu diyecekseniz, hepi topu 10 adres satır falan sildi.
bi 10 kadar adresde ben sildim. düşüre düşüre 18bin satırlara düşürdük elimizdeki dosyayı. ama şuan çok daha iyi.
ilerde neler olacak bilmiyorum. bakalım. elimden geldiğince geliştirmeye çalışacağım. ama yapay zeka motorlarıyla,
ve powershell ile zor. hatta baya bi zor. yamalı bohça gibi yani. en güzeli yine vbs miş onu bikez daha anladım.
zaten bende en çok reg tweak ve sonra vbs leri severim. geriside boş.
Betik Taslak İçeriği :
Kod: Tümünü seç
Line-Validator-And-Cleaner Manager Welcome...!
Ana Menü Seçenekleri ...
1.Kullanıcının tam yolunu verdiği dosyanın içeriğini göster
2.Dosyadan Kullanıcının İstemediği Veriyi SİL , Masaüstüne Kayıt Et.
3.Betikten Exit 0 Komutu İle Çık
Ne yapmak istiyorsun WindowsPC Kullanıcısı...?! = 2
Ana Menü Seçenek 2 seçildi...
Lütfen üzerinde değişiklik yapmak istediğiniz belge'nin tam yolunu girin : C:\Users\TRWE_2012\Masaüstü\DENEME DOSYASI.txt
Kullanıcıdan belge alındı analiz ediliyor...Tamam
Lütfen silmek isteklerinizi aralarına virgül koyarak yazın klaveyeden ENTER tuşuna basın (örnek : veri, veri2, veri3, VERİ4 gibi) : araba, ARABA2, deli, DELİ23 (kullancı enter tuşuna basar)
Lütfen bekleyin... Belge'den istenmeyenler siliniyor..İşlem tamam...Belge uzantısıyla birlikte yeni kopyası masaüstünde oluşturuldu.
Ana Menüye dönüş için R'ye betikten çıkmak için E'ye basın
POWERSHELL BETİKLERİ :
Türkçe Sürüm :
Kod: Tümünü seç
#Requires -Version 5.1
<#
Line-Validator-And-Cleaner Manager (Turkish version)
Console output encoding is pinned to UTF-8 below so Turkish characters
(i, s, g, u, o, c and their uppercase forms) render correctly on both
powershell.exe 5.1 and pwsh.exe 7+, regardless of the system chcp value.
#>
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
$OutputEncoding = New-Object System.Text.UTF8Encoding($false)
try { chcp 65001 > $null } catch { }
$TurkishCulture = [System.Globalization.CultureInfo]::GetCultureInfo("tr-TR")
function Show-MainMenu {
Clear-Host
Write-Host "==================================================="
Write-Host " Line-Validator-And-Cleaner Manager - Hoş Geldiniz"
Write-Host "==================================================="
Write-Host ""
Write-Host "Ana Menü Seçenekleri"
Write-Host ""
Write-Host "1. Kullanıcının tam yolunu verdiği dosyanın içeriğini göster"
Write-Host "2. Dosyadan Kullanıcının İstemediği Veriyi SİL, Masaüstüne Kayıt Et."
Write-Host "3. Betikten Exit 0 Komutu İle Çık"
Write-Host ""
}
function Read-ValidatedFilePath {
param(
[string]$PromptText = "Lütfen dosyanın tam yolunu girin"
)
while ($true) {
$path = Read-Host $PromptText
$path = $path.Trim('"').Trim()
if ([string]::IsNullOrWhiteSpace($path)) {
Write-Host "Yol boş olamaz. Lütfen tekrar deneyin." -ForegroundColor Yellow
continue
}
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
Write-Host "Belirtilen yolda dosya bulunamadı. Lütfen tekrar deneyin." -ForegroundColor Yellow
continue
}
return $path
}
}
function Wait-NavigationChoice {
while ($true) {
Write-Host ""
$nav = Read-Host "Ana Menüye dönüş için R'ye, betikten çıkmak için E'ye basın"
switch ($nav.Trim().ToUpper($TurkishCulture)) {
"R" { return "R" }
"E" { return "E" }
default { Write-Host "Geçersiz seçim. Lütfen R veya E girin." -ForegroundColor Yellow }
}
}
}
function Invoke-ShowFileContent {
$filePath = Read-ValidatedFilePath -PromptText "Lütfen görüntülemek istediğiniz dosyanın tam yolunu girin"
Write-Host ""
Write-Host "Kullanıcıdan belge alındı analiz ediliyor... Tamam"
Write-Host ""
Write-Host "---------------------------------------------------"
Get-Content -LiteralPath $filePath -Encoding UTF8
Write-Host "---------------------------------------------------"
}
function Remove-UnwantedTokenFromLine {
param(
[string]$Token,
[string]$Term,
[System.Globalization.CultureInfo]$Culture
)
$trimmedToken = $Token.Trim()
if ($trimmedToken -ceq $Term) { return $true }
if ($trimmedToken.ToLower($Culture) -eq $Term.ToLower($Culture)) { return $true }
if ($trimmedToken.Contains($Term)) { return $true }
if ($trimmedToken.ToLower($Culture).Contains($Term.ToLower($Culture))) { return $true }
return $false
}
function Invoke-CleanFile {
$filePath = Read-ValidatedFilePath -PromptText "Lütfen üzerinde değişiklik yapmak istediğiniz belgenin tam yolunu girin"
Write-Host ""
Write-Host "Kullanıcıdan belge alındı analiz ediliyor... Tamam"
Write-Host ""
$termsRaw = Read-Host "Lütfen silmek isteklerinizi aralarına virgül koyarak yazın klavyeden ENTER tuşuna basın (örnek: veri, veri2, veri3, VERİ4 gibi)"
$terms = $termsRaw.Split(",") | ForEach-Object { $_.Trim() } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
if ($terms.Count -eq 0) {
Write-Host "Herhangi bir arama terimi girilmedi, hiçbir değişiklik yapılmadı." -ForegroundColor Yellow
return
}
Write-Host ""
Write-Host "Lütfen bekleyin... Belgeden istenmeyenler siliniyor..."
$lines = Get-Content -LiteralPath $filePath -Encoding UTF8
$resultLines = New-Object System.Collections.Generic.List[string]
foreach ($line in $lines) {
$trimmedLine = $line.Trim()
$lineRemoved = $false
$workingLine = $line
foreach ($term in $terms) {
if ($trimmedLine -ceq $term) { $lineRemoved = $true; break }
if ($trimmedLine.ToLower($TurkishCulture) -eq $term.ToLower($TurkishCulture)) { $lineRemoved = $true; break }
$containsMatch = $workingLine.Contains($term) -or $workingLine.ToLower($TurkishCulture).Contains($term.ToLower($TurkishCulture))
if (-not $containsMatch) { continue }
if ($workingLine.Contains(",")) {
$tokens = $workingLine.Split(",") | ForEach-Object { $_.Trim() }
$tokens = $tokens | Where-Object { -not (Remove-UnwantedTokenFromLine -Token $_ -Term $term -Culture $TurkishCulture) }
if ($tokens.Count -eq 0) {
$lineRemoved = $true
break
} else {
$workingLine = ($tokens -join ", ")
}
} else {
$lineRemoved = $true
break
}
}
if (-not $lineRemoved) {
$resultLines.Add($workingLine)
}
}
$originalItem = Get-Item -LiteralPath $filePath
$desktopPath = [Environment]::GetFolderPath("Desktop")
$newFileName = "{0}_Temizlenmis{1}" -f $originalItem.BaseName, $originalItem.Extension
$newFilePath = Join-Path -Path $desktopPath -ChildPath $newFileName
Set-Content -LiteralPath $newFilePath -Value $resultLines -Encoding UTF8
Write-Host "İşlem tamam... Belge uzantısıyla birlikte yeni kopyası masaüstünde oluşturuldu."
Write-Host "Yeni dosya: $newFilePath"
}
$exitScript = $false
while (-not $exitScript) {
Show-MainMenu
$choice = Read-Host "Ne yapmak istiyorsun WindowsPC Kullanıcısı...?!"
switch ($choice.Trim()) {
"1" {
Write-Host ""
Write-Host "Ana Menü Seçenek 1 seçildi..."
Write-Host ""
Invoke-ShowFileContent
$nav = Wait-NavigationChoice
if ($nav -eq "E") { $exitScript = $true }
}
"2" {
Write-Host ""
Write-Host "Ana Menü Seçenek 2 seçildi..."
Write-Host ""
Invoke-CleanFile
$nav = Wait-NavigationChoice
if ($nav -eq "E") { $exitScript = $true }
}
"3" {
$exitScript = $true
}
default {
Write-Host ""
Write-Host "Geçersiz seçim, lütfen 1, 2 veya 3 girin." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
}
}
Write-Host ""
Write-Host "Line-Validator-And-Cleaner Manager kapatılıyor."
Read-Host "`nPress ENTER to exit."
exit 0
Kod: Tümünü seç
#Requires -Version 5.1
<#
Line-Validator-And-Cleaner Manager (English version)
A console menu tool that:
1) Displays the full content of a file the user points to.
2) Removes unwanted data from a file and saves a cleaned copy to the Desktop.
3) Exits the script with exit code 0.
Matching strategy for option 2 (adaptive, decided per line/term):
- Pass 1: exact match, case-sensitive (ordinal).
- Pass 2: exact match, Turkish-culture-aware case-insensitive.
- Pass 3: substring containment (case-sensitive, then Turkish-aware case-insensitive).
* If the line is a comma-separated list, only the matching token(s) are
removed and the remaining tokens are rejoined.
* If the line is a single data entry, the whole line is removed.
The script tries the strictest rule first and falls back progressively, so it
adapts automatically to how the term relates to each line, instead of forcing
one fixed matching mode for the whole file.
#>
$ErrorActionPreference = "Stop"
$TurkishCulture = [System.Globalization.CultureInfo]::GetCultureInfo("tr-TR")
function Show-MainMenu {
Clear-Host
Write-Host "==================================================="
Write-Host " Line-Validator-And-Cleaner Manager - Welcome"
Write-Host "==================================================="
Write-Host ""
Write-Host "Main Menu Options"
Write-Host ""
Write-Host "1. Show the content of a file at a path you provide"
Write-Host "2. Delete unwanted data from a file, save to Desktop"
Write-Host "3. Exit the script with code 0"
Write-Host ""
}
function Read-ValidatedFilePath {
param(
[string]$PromptText = "Please enter the full path of the file"
)
while ($true) {
$path = Read-Host $PromptText
$path = $path.Trim('"').Trim()
if ([string]::IsNullOrWhiteSpace($path)) {
Write-Host "Path cannot be empty. Please try again." -ForegroundColor Yellow
continue
}
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
Write-Host "File not found at that path. Please try again." -ForegroundColor Yellow
continue
}
return $path
}
}
function Wait-NavigationChoice {
while ($true) {
Write-Host ""
$nav = Read-Host "Press R to return to the Main Menu, or E to exit the script"
switch ($nav.Trim().ToUpperInvariant()) {
"R" { return "R" }
"E" { return "E" }
default { Write-Host "Invalid choice. Please enter R or E." -ForegroundColor Yellow }
}
}
}
function Invoke-ShowFileContent {
$filePath = Read-ValidatedFilePath -PromptText "Please enter the full path of the file you want to view"
Write-Host ""
Write-Host "File received from user, analyzing... OK"
Write-Host ""
Write-Host "---------------------------------------------------"
Get-Content -LiteralPath $filePath -Encoding UTF8
Write-Host "---------------------------------------------------"
}
function Remove-UnwantedTokenFromLine {
param(
[string]$Token,
[string]$Term,
[System.Globalization.CultureInfo]$Culture
)
$trimmedToken = $Token.Trim()
if ($trimmedToken -ceq $Term) { return $true }
if ($trimmedToken.ToLower($Culture) -eq $Term.ToLower($Culture)) { return $true }
if ($trimmedToken.Contains($Term)) { return $true }
if ($trimmedToken.ToLower($Culture).Contains($Term.ToLower($Culture))) { return $true }
return $false
}
function Invoke-CleanFile {
$filePath = Read-ValidatedFilePath -PromptText "Please enter the full path of the file you want to modify"
Write-Host ""
Write-Host "File received from user, analyzing... OK"
Write-Host ""
$termsRaw = Read-Host "Please enter the items to delete separated by commas, then press ENTER (example: data, data2, data3, DATA4)"
$terms = $termsRaw.Split(",") | ForEach-Object { $_.Trim() } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
if ($terms.Count -eq 0) {
Write-Host "No search terms were provided, nothing was changed." -ForegroundColor Yellow
return
}
Write-Host ""
Write-Host "Please wait... removing unwanted items from the file..."
$lines = Get-Content -LiteralPath $filePath -Encoding UTF8
$resultLines = New-Object System.Collections.Generic.List[string]
foreach ($line in $lines) {
$trimmedLine = $line.Trim()
$lineRemoved = $false
$workingLine = $line
foreach ($term in $terms) {
if ($trimmedLine -ceq $term) { $lineRemoved = $true; break }
if ($trimmedLine.ToLower($TurkishCulture) -eq $term.ToLower($TurkishCulture)) { $lineRemoved = $true; break }
$containsMatch = $workingLine.Contains($term) -or $workingLine.ToLower($TurkishCulture).Contains($term.ToLower($TurkishCulture))
if (-not $containsMatch) { continue }
if ($workingLine.Contains(",")) {
$tokens = $workingLine.Split(",") | ForEach-Object { $_.Trim() }
$tokens = $tokens | Where-Object { -not (Remove-UnwantedTokenFromLine -Token $_ -Term $term -Culture $TurkishCulture) }
if ($tokens.Count -eq 0) {
$lineRemoved = $true
break
} else {
$workingLine = ($tokens -join ", ")
}
} else {
$lineRemoved = $true
break
}
}
if (-not $lineRemoved) {
$resultLines.Add($workingLine)
}
}
$originalItem = Get-Item -LiteralPath $filePath
$desktopPath = [Environment]::GetFolderPath("Desktop")
$newFileName = "{0}_Cleaned{1}" -f $originalItem.BaseName, $originalItem.Extension
$newFilePath = Join-Path -Path $desktopPath -ChildPath $newFileName
Set-Content -LiteralPath $newFilePath -Value $resultLines -Encoding UTF8
Write-Host "Done. A new copy with the same extension was created on the Desktop."
Write-Host "New file: $newFilePath"
}
$exitScript = $false
while (-not $exitScript) {
Show-MainMenu
$choice = Read-Host "What would you like to do, WindowsPC User...?!"
switch ($choice.Trim()) {
"1" {
Write-Host ""
Write-Host "Main Menu Option 1 selected..."
Write-Host ""
Invoke-ShowFileContent
$nav = Wait-NavigationChoice
if ($nav -eq "E") { $exitScript = $true }
}
"2" {
Write-Host ""
Write-Host "Main Menu Option 2 selected..."
Write-Host ""
Invoke-CleanFile
$nav = Wait-NavigationChoice
if ($nav -eq "E") { $exitScript = $true }
}
"3" {
$exitScript = $true
}
default {
Write-Host ""
Write-Host "Invalid selection, please choose 1, 2 or 3." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
}
}
Write-Host ""
Write-Host "Exiting Line-Validator-And-Cleaner Manager."
Read-Host "`nPress ENTER to exit."
exit 0
Türkçe Sürüm :
Kod: Tümünü seç
Option Explicit
' Line-Validator-And-Cleaner Manager (Turkish version) - classic VBScript
'
' Must be run with cscript.exe (console host), e.g.:
' cscript //nologo Line-Validator-And-Cleaner-Manager_TR.vbs
' If launched with wscript.exe (no console), the script relaunches itself
' with cscript.exe automatically, below.
'
' Encoding note: classic VBScript / WSH has no Console.OutputEncoding-style
' API the way PowerShell does, so console output encoding cannot be pinned
' at runtime. To keep the Turkish characters below intact, this file is
' saved as UTF-16 LE with a BOM (native Unicode text), which the Windows
' Script Host parses reliably. For correct on-screen rendering, run the
' console with a Turkish locale codepage, or set the terminal to UTF-8
' (chcp 65001) with a font that covers Turkish characters before running
' cscript.
Dim fso, shellApp
Set fso = CreateObject("Scripting.FileSystemObject")
Set shellApp = CreateObject("WScript.Shell")
' wscript.exe ile başlatılmışsa, cscript.exe ile yeniden başlat.
If InStr(1, LCase(WScript.FullName), "wscript.exe") > 0 Then
shellApp.Run "cscript.exe //nologo """ & WScript.ScriptFullName & """", 1, False
WScript.Quit 0
End If
' Herhangi bir StdIn/StdOut etkileşiminden önce aktif konsolu UTF-8 kod
' sayfasına (65001) geçirmeyi dener. Klasik WSH'de PowerShell'deki gibi
' bir Console.InputEncoding API'si yok, bu yüzden klavyeden yazılan
' Türkçe karakterler konsolun varsayılan kod sayfasından yanlış okunabilir.
' Bu adım en iyi çaba (best-effort) niteliğindedir: başarısız olursa
' betik yine çalışır, ancak elle yazılan Türkçe yollar eşleşmeyebilir.
On Error Resume Next
shellApp.Run "%comspec% /c chcp 65001>nul", 0, True
On Error Goto 0
' Komut satırı argümanı olarak verilen bir dosya yolu (bu .vbs dosyasının
' üzerine sürükle-bırak yapılarak, ya da
' `cscript //nologo betik.vbs "C:\yol\dosya.txt"` şeklinde çalıştırılarak)
' doğrudan işletim sisteminin komut satırından okunur ve yukarıdaki konsol
' kod sayfası sorunundan ETKİLENMEZ. Karşılaşılan ilk yol isteminde bir
' kez kullanılır, ardından temizlenir.
Dim pendingArgPath
pendingArgPath = ""
If WScript.Arguments.Count > 0 Then
pendingArgPath = WScript.Arguments(0)
End If
Dim exitScript
exitScript = False
Do While Not exitScript
ShowMainMenu
Dim choice
WScript.StdOut.Write "Ne yapmak istiyorsun WindowsPC Kullanıcısı...?! = "
choice = Trim(WScript.StdIn.ReadLine())
Select Case choice
Case "1"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Ana Menü Seçenek 1 seçildi..."
WScript.StdOut.WriteLine ""
ShowFileContent
If NavigationChoice() = "E" Then exitScript = True
Case "2"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Ana Menü Seçenek 2 seçildi..."
WScript.StdOut.WriteLine ""
CleanFile
If NavigationChoice() = "E" Then exitScript = True
Case "3"
exitScript = True
Case Else
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Geçersiz seçim, lütfen 1, 2 veya 3 girin."
WScript.Sleep 800
End Select
Loop
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Line-Validator-And-Cleaner Manager kapatılıyor."
WScript.StdOut.Write vbCrLf & "Press ENTER to exit."
WScript.StdIn.ReadLine()
WScript.Quit 0
' ---------------------------------------------------------------------------
Sub ShowMainMenu
WScript.StdOut.WriteLine "==================================================="
WScript.StdOut.WriteLine " Line-Validator-And-Cleaner Manager - Hoş Geldiniz"
WScript.StdOut.WriteLine "==================================================="
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Ana Menü Seçenekleri"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "1. Kullanıcının tam yolunu verdiği dosyanın içeriğini göster"
WScript.StdOut.WriteLine "2. Dosyadan Kullanıcının İstemediği Veriyi SİL, Masaüstüne Kayıt Et."
WScript.StdOut.WriteLine "3. Betikten Exit 0 Komutu İle Çık"
WScript.StdOut.WriteLine ""
End Sub
Function NavigationChoice()
Dim nav
Do
WScript.StdOut.Write vbCrLf & "Ana Menüye dönüş için R'ye, betikten çıkmak için E'ye basın : "
nav = UCase(Trim(WScript.StdIn.ReadLine()))
If nav = "R" Or nav = "E" Then
NavigationChoice = nav
Exit Function
Else
WScript.StdOut.WriteLine "Geçersiz seçim. Lütfen R veya E girin."
End If
Loop
End Function
Function StripQuotes(s)
Dim result
result = s
If Len(result) >= 2 Then
If Left(result, 1) = Chr(34) And Right(result, 1) = Chr(34) Then
result = Mid(result, 2, Len(result) - 2)
End If
End If
StripQuotes = result
End Function
Function ReadValidatedFilePath(promptText)
Dim p
If pendingArgPath <> "" Then
p = StripQuotes(pendingArgPath)
pendingArgPath = ""
If fso.FileExists(p) Then
ReadValidatedFilePath = p
Exit Function
Else
WScript.StdOut.WriteLine "Komut satırı argümanı olarak verilen yol bulunamadı. Lütfen elle girin."
End If
End If
Do
WScript.StdOut.Write promptText & " : "
p = Trim(WScript.StdIn.ReadLine())
p = StripQuotes(p)
If p = "" Then
WScript.StdOut.WriteLine "Yol boş olamaz. Lütfen tekrar deneyin."
ElseIf Not fso.FileExists(p) Then
WScript.StdOut.WriteLine "Belirtilen yolda dosya bulunamadı. Lütfen tekrar deneyin."
Else
ReadValidatedFilePath = p
Exit Function
End If
Loop
End Function
Function ReadFileUTF8(path)
Dim stream
Set stream = CreateObject("ADODB.Stream")
stream.Type = 2 ' adTypeText
stream.Charset = "utf-8"
stream.Open
stream.LoadFromFile path
ReadFileUTF8 = stream.ReadText
stream.Close
End Function
Function SplitLines(content)
Dim normalized
normalized = Replace(content, vbCrLf, vbLf)
normalized = Replace(normalized, vbCr, vbLf)
SplitLines = Split(normalized, vbLf)
End Function
Sub WriteLinesUTF8(path, arrLines)
Dim stream, i, content
content = ""
If UBound(arrLines) >= 0 Then
For i = 0 To UBound(arrLines)
content = content & arrLines(i)
If i < UBound(arrLines) Then content = content & vbCrLf
Next
End If
Set stream = CreateObject("ADODB.Stream")
stream.Type = 2 ' adTypeText
stream.Charset = "utf-8"
stream.Open
stream.WriteText content
stream.SaveToFile path, 2 ' adSaveCreateOverWrite
stream.Close
End Sub
Sub ShowFileContent
Dim path, content, lines, i
path = ReadValidatedFilePath("Lütfen görüntülemek istediğiniz dosyanın tam yolunu girin")
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Kullanıcıdan belge alındı analiz ediliyor... Tamam"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "---------------------------------------------------"
content = ReadFileUTF8(path)
lines = SplitLines(content)
For i = 0 To UBound(lines)
WScript.StdOut.WriteLine lines(i)
Next
WScript.StdOut.WriteLine "---------------------------------------------------"
End Sub
Function TokenMatchesTerm(token, term)
Dim t
t = Trim(token)
If StrComp(t, term, vbBinaryCompare) = 0 Then
TokenMatchesTerm = True
Exit Function
End If
If StrComp(t, term, vbTextCompare) = 0 Then
TokenMatchesTerm = True
Exit Function
End If
If InStr(1, t, term, vbBinaryCompare) > 0 Then
TokenMatchesTerm = True
Exit Function
End If
If InStr(1, t, term, vbTextCompare) > 0 Then
TokenMatchesTerm = True
Exit Function
End If
TokenMatchesTerm = False
End Function
Sub CleanFile
Dim path, content, lines, termsRaw, rawTermsArr, terms, termCount, i, j, k
Dim resultLines, resultCount
Dim line, trimmedLine, lineRemoved, workingLine, term, containsMatch
Dim tokens, filteredTokens, filteredCount
Dim originalName, originalExt, newFileName, desktopPath, newFilePath
path = ReadValidatedFilePath("Lütfen üzerinde değişiklik yapmak istediğiniz belgenin tam yolunu girin")
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Kullanıcıdan belge alındı analiz ediliyor... Tamam"
WScript.StdOut.WriteLine ""
WScript.StdOut.Write "Lütfen silmek isteklerinizi aralarına virgül koyarak yazın klavyeden ENTER tuşuna basın (örnek: veri, veri2, veri3, VERİ4 gibi) : "
termsRaw = WScript.StdIn.ReadLine()
rawTermsArr = Split(termsRaw, ",")
ReDim terms(UBound(rawTermsArr))
termCount = 0
For i = 0 To UBound(rawTermsArr)
Dim candidateTerm
candidateTerm = Trim(rawTermsArr(i))
If candidateTerm <> "" Then
terms(termCount) = candidateTerm
termCount = termCount + 1
End If
Next
If termCount = 0 Then
WScript.StdOut.WriteLine "Herhangi bir arama terimi girilmedi, hiçbir değişiklik yapılmadı."
Exit Sub
End If
ReDim Preserve terms(termCount - 1)
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Lütfen bekleyin... Belgeden istenmeyenler siliniyor..."
content = ReadFileUTF8(path)
lines = SplitLines(content)
ReDim resultLines(UBound(lines))
resultCount = 0
For i = 0 To UBound(lines)
line = lines(i)
trimmedLine = Trim(line)
lineRemoved = False
workingLine = line
For j = 0 To UBound(terms)
term = terms(j)
If StrComp(trimmedLine, term, vbBinaryCompare) = 0 Then
lineRemoved = True
Exit For
End If
If StrComp(trimmedLine, term, vbTextCompare) = 0 Then
lineRemoved = True
Exit For
End If
containsMatch = (InStr(1, workingLine, term, vbBinaryCompare) > 0) Or (InStr(1, workingLine, term, vbTextCompare) > 0)
If containsMatch Then
If InStr(1, workingLine, ",") > 0 Then
tokens = Split(workingLine, ",")
ReDim filteredTokens(UBound(tokens))
filteredCount = 0
For k = 0 To UBound(tokens)
If Not TokenMatchesTerm(tokens(k), term) Then
filteredTokens(filteredCount) = Trim(tokens(k))
filteredCount = filteredCount + 1
End If
Next
If filteredCount = 0 Then
lineRemoved = True
Exit For
Else
ReDim Preserve filteredTokens(filteredCount - 1)
workingLine = Join(filteredTokens, ", ")
End If
Else
lineRemoved = True
Exit For
End If
End If
Next
If Not lineRemoved Then
resultLines(resultCount) = workingLine
resultCount = resultCount + 1
End If
Next
If resultCount = 0 Then
ReDim resultLines(-1)
Else
ReDim Preserve resultLines(resultCount - 1)
End If
originalName = fso.GetBaseName(path)
originalExt = fso.GetExtensionName(path)
desktopPath = shellApp.SpecialFolders("Desktop")
If originalExt <> "" Then
newFileName = originalName & "_Temizlenmiş." & originalExt
Else
newFileName = originalName & "_Temizlenmiş"
End If
newFilePath = fso.BuildPath(desktopPath, newFileName)
WriteLinesUTF8 newFilePath, resultLines
WScript.StdOut.WriteLine "İşlem tamam... Belge uzantısıyla birlikte yeni kopyası masaüstünde oluşturuldu."
WScript.StdOut.WriteLine "Yeni dosya: " & newFilePath
End Sub
Kod: Tümünü seç
Option Explicit
' Line-Validator-And-Cleaner Manager (English version) - classic VBScript
'
' Must be run with cscript.exe (console host), e.g.:
' cscript //nologo Line-Validator-And-Cleaner-Manager_EN.vbs
' If launched with wscript.exe (no console), the script relaunches itself
' with cscript.exe automatically, below.
'
' Menu:
' 1) Show the content of a file at a path the user provides.
' 2) Remove unwanted data from a file, save a cleaned copy to Desktop.
' 3) Exit the script with code 0.
'
' Matching strategy for option 2 (adaptive, decided per line/term):
' - Pass 1: exact match, case-sensitive (vbBinaryCompare).
' - Pass 2: exact match, locale-aware case-insensitive (vbTextCompare).
' - Pass 3: substring containment (vbBinaryCompare, then vbTextCompare).
' * If the line is a comma-separated list, only the matching token(s)
' are removed and the remaining tokens are rejoined.
' * If the line is a single data entry, the whole line is removed.
' The script tries the strictest rule first and falls back progressively, so
' it adapts to how each term relates to each line instead of using one fixed
' matching mode for the whole file.
Dim fso, shellApp
Set fso = CreateObject("Scripting.FileSystemObject")
Set shellApp = CreateObject("WScript.Shell")
' Relaunch under cscript.exe if this was started with wscript.exe.
If InStr(1, LCase(WScript.FullName), "wscript.exe") > 0 Then
shellApp.Run "cscript.exe //nologo """ & WScript.ScriptFullName & """", 1, False
WScript.Quit 0
End If
' Try to switch the active console to UTF-8 (codepage 65001) before any
' StdIn/StdOut interaction. Classic WSH has no Console.InputEncoding API,
' so typed non-ASCII characters (accented letters, etc.) can otherwise be
' misread from the console's default codepage. This is best-effort: if it
' fails, the script still works, but typed non-ASCII paths may not match.
On Error Resume Next
shellApp.Run "%comspec% /c chcp 65001>nul", 0, True
On Error Goto 0
' A file path passed as a command-line argument (drag-and-drop onto this
' .vbs file, or `cscript //nologo script.vbs "C:\path\to\file.txt"`) is
' read directly from the OS command line and is NOT affected by the
' console codepage problem above. It is used once, for the first path
' prompt encountered, then cleared.
Dim pendingArgPath
pendingArgPath = ""
If WScript.Arguments.Count > 0 Then
pendingArgPath = WScript.Arguments(0)
End If
Dim exitScript
exitScript = False
Do While Not exitScript
ShowMainMenu
Dim choice
WScript.StdOut.Write "What would you like to do, WindowsPC User...?! = "
choice = Trim(WScript.StdIn.ReadLine())
Select Case choice
Case "1"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Main Menu Option 1 selected..."
WScript.StdOut.WriteLine ""
ShowFileContent
If NavigationChoice() = "E" Then exitScript = True
Case "2"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Main Menu Option 2 selected..."
WScript.StdOut.WriteLine ""
CleanFile
If NavigationChoice() = "E" Then exitScript = True
Case "3"
exitScript = True
Case Else
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Invalid selection, please choose 1, 2 or 3."
WScript.Sleep 800
End Select
Loop
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Exiting Line-Validator-And-Cleaner Manager."
WScript.StdOut.Write vbCrLf & "Press ENTER to exit."
WScript.StdIn.ReadLine()
WScript.Quit 0
' ---------------------------------------------------------------------------
Sub ShowMainMenu
WScript.StdOut.WriteLine "==================================================="
WScript.StdOut.WriteLine " Line-Validator-And-Cleaner Manager - Welcome"
WScript.StdOut.WriteLine "==================================================="
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Main Menu Options"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "1. Show the content of a file at a path you provide"
WScript.StdOut.WriteLine "2. Delete unwanted data from a file, save to Desktop"
WScript.StdOut.WriteLine "3. Exit the script with code 0"
WScript.StdOut.WriteLine ""
End Sub
Function NavigationChoice()
Dim nav
Do
WScript.StdOut.Write vbCrLf & "Press R to return to the Main Menu, or E to exit the script : "
nav = UCase(Trim(WScript.StdIn.ReadLine()))
If nav = "R" Or nav = "E" Then
NavigationChoice = nav
Exit Function
Else
WScript.StdOut.WriteLine "Invalid choice. Please enter R or E."
End If
Loop
End Function
Function StripQuotes(s)
Dim result
result = s
If Len(result) >= 2 Then
If Left(result, 1) = Chr(34) And Right(result, 1) = Chr(34) Then
result = Mid(result, 2, Len(result) - 2)
End If
End If
StripQuotes = result
End Function
Function ReadValidatedFilePath(promptText)
Dim p
If pendingArgPath <> "" Then
p = StripQuotes(pendingArgPath)
pendingArgPath = ""
If fso.FileExists(p) Then
ReadValidatedFilePath = p
Exit Function
Else
WScript.StdOut.WriteLine "The path passed as a command-line argument was not found. Please enter it manually."
End If
End If
Do
WScript.StdOut.Write promptText & " : "
p = Trim(WScript.StdIn.ReadLine())
p = StripQuotes(p)
If p = "" Then
WScript.StdOut.WriteLine "Path cannot be empty. Please try again."
ElseIf Not fso.FileExists(p) Then
WScript.StdOut.WriteLine "File not found at that path. Please try again."
Else
ReadValidatedFilePath = p
Exit Function
End If
Loop
End Function
Function ReadFileUTF8(path)
Dim stream
Set stream = CreateObject("ADODB.Stream")
stream.Type = 2 ' adTypeText
stream.Charset = "utf-8"
stream.Open
stream.LoadFromFile path
ReadFileUTF8 = stream.ReadText
stream.Close
End Function
Function SplitLines(content)
Dim normalized
normalized = Replace(content, vbCrLf, vbLf)
normalized = Replace(normalized, vbCr, vbLf)
SplitLines = Split(normalized, vbLf)
End Function
Sub WriteLinesUTF8(path, arrLines)
Dim stream, i, content
content = ""
If UBound(arrLines) >= 0 Then
For i = 0 To UBound(arrLines)
content = content & arrLines(i)
If i < UBound(arrLines) Then content = content & vbCrLf
Next
End If
Set stream = CreateObject("ADODB.Stream")
stream.Type = 2 ' adTypeText
stream.Charset = "utf-8"
stream.Open
stream.WriteText content
stream.SaveToFile path, 2 ' adSaveCreateOverWrite
stream.Close
End Sub
Sub ShowFileContent
Dim path, content, lines, i
path = ReadValidatedFilePath("Please enter the full path of the file you want to view")
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "File received from user, analyzing... OK"
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "---------------------------------------------------"
content = ReadFileUTF8(path)
lines = SplitLines(content)
For i = 0 To UBound(lines)
WScript.StdOut.WriteLine lines(i)
Next
WScript.StdOut.WriteLine "---------------------------------------------------"
End Sub
Function TokenMatchesTerm(token, term)
Dim t
t = Trim(token)
If StrComp(t, term, vbBinaryCompare) = 0 Then
TokenMatchesTerm = True
Exit Function
End If
If StrComp(t, term, vbTextCompare) = 0 Then
TokenMatchesTerm = True
Exit Function
End If
If InStr(1, t, term, vbBinaryCompare) > 0 Then
TokenMatchesTerm = True
Exit Function
End If
If InStr(1, t, term, vbTextCompare) > 0 Then
TokenMatchesTerm = True
Exit Function
End If
TokenMatchesTerm = False
End Function
Sub CleanFile
Dim path, content, lines, termsRaw, rawTermsArr, terms, termCount, i, j, k
Dim resultLines, resultCount
Dim line, trimmedLine, lineRemoved, workingLine, term, containsMatch
Dim tokens, filteredTokens, filteredCount
Dim originalName, originalExt, newFileName, desktopPath, newFilePath
path = ReadValidatedFilePath("Please enter the full path of the file you want to modify")
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "File received from user, analyzing... OK"
WScript.StdOut.WriteLine ""
WScript.StdOut.Write "Please enter the items to delete separated by commas, then press ENTER (example: data, data2, data3, DATA4) : "
termsRaw = WScript.StdIn.ReadLine()
rawTermsArr = Split(termsRaw, ",")
ReDim terms(UBound(rawTermsArr))
termCount = 0
For i = 0 To UBound(rawTermsArr)
Dim candidateTerm
candidateTerm = Trim(rawTermsArr(i))
If candidateTerm <> "" Then
terms(termCount) = candidateTerm
termCount = termCount + 1
End If
Next
If termCount = 0 Then
WScript.StdOut.WriteLine "No search terms were provided, nothing was changed."
Exit Sub
End If
ReDim Preserve terms(termCount - 1)
WScript.StdOut.WriteLine ""
WScript.StdOut.WriteLine "Please wait... removing unwanted items from the file..."
content = ReadFileUTF8(path)
lines = SplitLines(content)
ReDim resultLines(UBound(lines))
resultCount = 0
For i = 0 To UBound(lines)
line = lines(i)
trimmedLine = Trim(line)
lineRemoved = False
workingLine = line
For j = 0 To UBound(terms)
term = terms(j)
If StrComp(trimmedLine, term, vbBinaryCompare) = 0 Then
lineRemoved = True
Exit For
End If
If StrComp(trimmedLine, term, vbTextCompare) = 0 Then
lineRemoved = True
Exit For
End If
containsMatch = (InStr(1, workingLine, term, vbBinaryCompare) > 0) Or (InStr(1, workingLine, term, vbTextCompare) > 0)
If containsMatch Then
If InStr(1, workingLine, ",") > 0 Then
tokens = Split(workingLine, ",")
ReDim filteredTokens(UBound(tokens))
filteredCount = 0
For k = 0 To UBound(tokens)
If Not TokenMatchesTerm(tokens(k), term) Then
filteredTokens(filteredCount) = Trim(tokens(k))
filteredCount = filteredCount + 1
End If
Next
If filteredCount = 0 Then
lineRemoved = True
Exit For
Else
ReDim Preserve filteredTokens(filteredCount - 1)
workingLine = Join(filteredTokens, ", ")
End If
Else
lineRemoved = True
Exit For
End If
End If
Next
If Not lineRemoved Then
resultLines(resultCount) = workingLine
resultCount = resultCount + 1
End If
Next
If resultCount = 0 Then
ReDim resultLines(-1)
Else
ReDim Preserve resultLines(resultCount - 1)
End If
originalName = fso.GetBaseName(path)
originalExt = fso.GetExtensionName(path)
desktopPath = shellApp.SpecialFolders("Desktop")
If originalExt <> "" Then
newFileName = originalName & "_Cleaned." & originalExt
Else
newFileName = originalName & "_Cleaned"
End If
newFilePath = fso.BuildPath(desktopPath, newFileName)
WriteLinesUTF8 newFilePath, resultLines
WScript.StdOut.WriteLine "Done. A new copy with the same extension was created on the Desktop."
WScript.StdOut.WriteLine "New file: " & newFilePath
End Sub
Kod: Tümünü seç
cscript //nologo "C:\Users\TRWE_2012\Masaüstü\Line-Validator-And-Cleaner-Manager_TR.vbs" "C:\Users\TRWE_2012\Masaüstü\Powershell_VBS BETİĞİ İsteği - Tasklak.txt"Kod: Tümünü seç
cscript //nologo "BETİĞİN TAM TOLU" "DEĞİŞTİRİLMEK İSTENİLEN BELGE.DOSYA UZANTISI"Ekran Görüntüsü :


