$getlist = (Get-Content \searchlist.txt) -as [string[]]
foreach ($word in $getlist) {
$list = "*" + $word +"*"
$link = "\findfolder\"
$file = $link + $list
if(Test-Path $file)
{
Write-Host "見つかったワード:" $word
Write-Host "コピーして移動しました:" $word
}
else
{
Write-Host "見つからなかったワード:" $word
Write-Output $word | Out-File -Append "\folderreadcopy\out.txt"
}
}
# 処理対象のフォルダ
$targetFolder = "\findfolder"
# コピー先のフォルダ
$destinationPath = "\copyfolder"
# $targetFolder内のファイル・フォルダのリストを取得する。
$itemList = Get-ChildItem $targetFolder;
foreach($item in $itemList)
{
if($item.PSIsContainer)
{
# フォルダの場合の処理
Write-Host ($item.Name + 'はフォルダです。');
}
else
{
# ファイルの場合の処理
# 拡張子を除いたファイル名を$str_file_name_without_extここにいれる
$str_file_name_without_ext = [System.IO.Path]::GetFileNameWithoutExtension($item);
Write-Host ($str_file_name_without_ext + 'はファイルです。');
# $fileにin.txtにあるリストをすべて代入
$file = (Get-Content \searchlist.txt) -as [string[]]
# $str_file_name_without_extに$fileのリストの文字が含まれていればtrue含まれていない場合はfalse
foreach ($l in $file)
{
if($str_file_name_without_ext.Contains($l))
{
$copymoto = "\findfolder\" + $item
Copy-Item -Path $copymoto -Destination $destinationPath
}
}
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme