I have a list of 200 filenames. I need to find these files, which are located in different subfolders, by their filename and copy them into one separate folder. I'm using Windows 7. How do I do that?
Thanks, Natalya
I have a list of 200 filenames. I need to find these files, which are located in different subfolders, by their filename and copy them into one separate folder. I'm using Windows 7. How do I do that?
Thanks, Natalya
My suggestion is to go to Ninite.com, and download the freeware tool called "Everything". it's a simple windows search tool. After install, give it 5 minutes or so to index your files.
In the search field, type your search term, and you'll get instant results, like you do on Google. Upon seeing the results, you can then manipulate the files directly in the Everything search window, such as you can in Windows explorer. You could 'select all' and then copy them, and then in Win Explorer go to the folder you want them and paste them.
Everything is a really nice tool. You don't even need to type the entire filename, just part of it, e.g. 'eag mp3' will return all MP3's with 'eag' in the filename, such as 'eagles - song name.mp3'
Here you go. Do the dry run first. Read comments carefully.
The file fullfilenames.txt will persist so you have a record of each file that was found. If you need to run this more than once and want to keep the file either move or rename it.
A logfile 'movelog.txt' will be created. As above, either move or rename it if you want to keep it after each run.
# Set your search directory and destination directory
$destdir = "[destination for files]"
$searchdir = "[top dir of search path]"
# Create empty file to contain the full path info for each file
echo $null > fullfilenames.txt
# Create array from your list of filenames
$filenames = Get-Content filenames.txt
# For each file in array of filenames get fullpath and assign var $fullname
foreach ($file in $filenames) {
$fullname = Get-ChildItem $searchdir | Where-Object {$_.PSIsContainer -eq $False -and ($_.Name) -eq $file} | ForEach-Object {$_.FullName}
# Add full path of file to fullfilenames.txt
echo $fullname >> fullfilenames.txt
# Uncomment next two lines for troubleshooting & dry run
#echo $file
#Write-Host $fullname
}
# Create array from new list of files with full path info and then move each file to destination.
# For troubleshooting & dry run, comment out following two lines.
$filenames = Get-Content fullfilenames.txt
echo $null > movelog.txt
foreach ( $file in $filenames ) {
Move-Item $file $destdir
# Log success/fail of each move
echo "$(Get-Date -f o) $? $file" >> movelog.txt
}
Note: This is a powershell script. Save it as whatever.ps1 and run it in the PowerShell console.
Enjoy
You can search for a list of files in "Everything" by delimiting with |
.
For example: file1|file2|file3|file4
Link to dowload "Everything": https://www.voidtools.com/downloads/