Solved

How to move files with specific text in filename

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

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 79

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Set OWA language and time zone in Exchange for individuals, all users or per database.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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