Move file listed on csv file

Hello,

I have folder with 3 millions files. Files names format is 123_456_Name_country.pdf

First part = Candidate id
Second Part = Job ID
I have csv files which have candidate id in format
candidateid,
123,
345,
321

total number of Candidate ID on csv file is around 12000.

Source Folder = D:\Source where all 3 millions files are

I need powershell scripts which will move file to D:\Dest folder with all the candidateid in CSV files.
Can anyone help me .

 

 

Hi Kundan,

Did you try anything? Please post your code, then we can suggest you as needed. Writing code from scratch is a bit difficult here.

Thank you.

Maybe something like import IDs from csv to variable. Use this variable in the get-childitem include parameter and pipe the outcome to move-item. Please try first, post your code and then we can help. It’s quite a simple one in the end if you put any effort in trying.

Hello Kiran,
THis is what I have but it does not work

$Files = Get-childitem -Path d:\source

$CandidateIDs = Import-CSV d:\source\candidate.csv

ForEach($File in $Files){

ForEach($ID in $CadidateIDs){

If(($File.Name.Substring(0,3)) -eq $ID.candidateid){

$MovedFile = “d:\dest” + $File.Name

move-item $File.FullName $MovedFile

}

}

}

 

Would this match the need?

[pre]

$IDs = Import-Csv “d:\source\candidate.csv” | select -ExpandProperty candidateid
$filter = $IDs | foreach {"$($_.substring(0,3))*"}

Get-ChildItem “d:\source*” -Include $filter | select -expand fullname | Move-Item -Destination “d:\dest”
[/pre]

edit from import-certificate to import-csv

I receive the error message

Import-Certificate : Cannot validate argument on parameter ‘Context’. The argument “d:\source\candidate.csv” does not belong to the set “CurrentUser,LocalMachine” specified by the
ValidateSet attribute. Supply an argument that is in the set and then try the command again.
At line:1 char:27

  • $IDs = Import-Certificate d:\source\candidate.csv | select -ExpandPro …
  • CategoryInfo : InvalidData: (:slight_smile: [Import-Certificate], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Import-Certificate

You cannot call a method on a null-valued expression.
At line:2 char:30

  • $filter = $IDs | foreach {"$($_.substring(0,3))*"}
  • CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException
  • FullyQualifiedErrorId : InvokeMethodOnNull

But it odes copy all files and not only files on the csv

 

# move pdf files that start with candidateid in filename
$CandidateID = (Import-CSV d:\source\candidate.csv).candidateid

foreach ($c in $CandidateID){
Get-ChildItem -Path "d:\source" -Filter $c*.pdf |
move-Item -Destination "d:\dest"}

Thank you . This is exactly what i was looking for

 

tab completion error :smiley:

[pre]

$IDs = Import-csv “d:\source\candidate.csv” | select -ExpandProperty candidateid
$filter = $IDs | foreach {"$($_.substring(0,3))*"}

Get-ChildItem “d:\source*” -Include $filter | select -expand fullname | Move-Item -Destination “d:\dest”

[/pre]