Solved

How to move files with specific text in filename

Posted on 2016-08-07
5
48 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

12 Experts available now in Live!

Get 1:1 Help Now