Solved

How to move files with specific text in filename

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

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 80

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 80

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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