Skip to content

Instantly share code, notes, and snippets.

@skkut
Last active November 7, 2018 11:01
Show Gist options
  • Save skkut/b920cd146b3abe80c6c634ab8da9ef51 to your computer and use it in GitHub Desktop.
Save skkut/b920cd146b3abe80c6c634ab8da9ef51 to your computer and use it in GitHub Desktop.
Identify files that are not backed up and move them to a new sub folder. Already backed up filenames are in filelist.txt
$dir = 'D:\sample_folder'
$FileList = $dir + '\filelist.txt'
$BackupFolderName = (get-item $dir).BaseName + " Backup"
$BackupFolder = Join-Path $dir $BackupFolderName
New-Item -ItemType Directory -Force -Path $BackupFolder
$BackedFiles = Get-Content $FileList
$Files = Get-ChildItem -Path $dir -File
foreach ($file in $Files)
{
if($BackedFiles -notcontains $file.Name)
{Move-Item $dir\$file $BackupFolder}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment