How to mapping a folder name using PowerShell?

那年仲夏 提交于 2020-03-05 00:23:13

问题


I want to mapping an a folder to download and extract the folder. This is the way I need to download the folder.

DownloadF.exe --net 10.0.0.1 --user XX --id 00 --ver A00X-F1A >> result.txt

I have 26 version to mapping, which are

A00X-F1A ... A00X-F1Z (the last character is A - Z)

If the result.txt contain of this string "folder available". It means the version is correct, then stop the looping or checking other version.

I must check the version start from A00X-F1Z, A00X-F1Y, A00X-F1X, ... A00X-F1A. Anyone can give me idea please.

##Updated
$Version = "A00X-F1"
$List_Ver = 90..65 | ForEach-Object{"$Version" + [char]$_}
$n = 0
foreach ($list in $List_Ver){    
    while ($Result -notcontains "Folder Available")
    {
        $n++
        & DownloadF.exe --net 10.0.0.1 --user XX --id 00 --ver $list >> $list.txt"
        Start-Sleep -s 3
        $Result = Get-Content -path .\$list.txt
    }
}

回答1:


This is what I tested with what I gather you are looking for,

Sample result.txt

A00X-F1Z
A00X-F1Y
A00X-F1X
A00X-F1W
A00X-F1V
A00X-F1U
A00X-F1T
A00X-F1S
A00X-F1R
A00X-F1Q

Code to work with

$Version = "A00X-F1"
$List_Ver = 90..65 | ForEach-Object{"$Version" + [char]$_}
$result = Get-Content C:\temp\result.txt 
$string = "Folder Not Available"
foreach($list in $List_Ver) {
DownloadF.exe --net 10.0.0.1 --user XX --id 00 --ver $list >> result.txt
  if ($result -like $string ) {
    $n = 0
    while ($result -like $string)
    {
      $n++

     Write-Host "Not Found"
     Break
}
  }
  else {
     Write-Host "Found"
     Break
  }
}


来源:https://stackoverflow.com/questions/60203036/how-to-mapping-a-folder-name-using-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!