Avatar of Brent Guttmann
Brent Guttmann
Flag for United States of America asked on

How to move files with specific text in filename

Hi, 2 basic questions regarding powershell:

1. How can I use powershell to move all files in 1 folder that have "_CLM_" in the file name  (on network server)

2. How can I use powershell to move a csv list of files from 1 directory to another? (if they are in different folders within 1 directory... and also on a network server)

Avatar of undefined
Last Comment
Brent Guttmann

8/22/2022 - Mon

1. Similar to moving tif files,  just with a different filter:
Get-ChildItem C:\Temp -Path C:\Temp -Filter "*_CLM_*" | Move-Item -Destination D:\Target -WhatIf 

Open in new window

2. The basic command to read a csv file is "Import-Csv -Path C:\Temp\SomeFile.csv"; this will get you an array of objects with the column names as properties, provided the csv file has a header line. If it doesn't, you need to provide the -Header argument to let PS know about the column names.
It's unclear what you want to do - does the csv file have a source and target column for each individual file, or just a source and you want all files to go under a common target location? And if the latter, do you want to "flatten" the source subfolder structure (and if so, what is supposed to happen with duplicate names), or keep it in the target?
David Johnson, CD

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Brent Guttmann

Hi, when I tried testing this, after I pasted the code into powershell and pressed enter it just went to the next line, which read ">>" and thats it.... nothing happened. What am I doing wrong?

import-csv c:\temp\filelist.csv | foreach {move-item $_.filename -destination C:\Temp\test\
David Johnson, CD

import-csv c:\temp\filelist.csv | foreach {move-item $_.filename -destination C:\Temp\test\  }

Open in new window

missing close bracket
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Brent Guttmann

whoops! haha, thanks for your help