Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to move files with specific text in filename

Posted on 2016-08-07
5
Medium Priority
?
69 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 85

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 83

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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 83

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

610 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