Solved

How to move files with specific text in filename

Posted on 2016-08-07
5
50 Views
Last Modified: 2016-08-13
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)
0
Comment
Question by:Brent Guttmann
  • 2
  • 2
5 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 41746667
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?
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41746700

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

$source = 'c:\test\source'
$dest = 'd:\dest'
get-childitem -Path C:\test\* -Include '*_CLM_*' | select-object name,fullname | % { $_.FullName; move-item -path $_.FullName  -destination ( $dest + '\' + $_.Name) }

Open in new window


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)

import-csv c:\test\filelist.csv | foreach {move-item $_.filename -destination d:\test\ 

Open in new window

}
0
 

Author Comment

by:Brent Guttmann
ID: 41754461
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\
0
 
LVL 78

Expert Comment

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

Open in new window

missing close bracket
0
 

Author Comment

by:Brent Guttmann
ID: 41754805
whoops! haha, thanks for your help
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A brief introduction to what I consider to be the best editor for PowerShell.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now