Move file listed on csv file

Welcome Forums General PowerShell Q&A Move file listed on csv file

Viewing 9 reply threads
  • Author
    Posts
    • #192622
      Participant
      Topics: 1
      Replies: 4
      Points: 20
      Rank: Member

      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 .

       

       

    • #192652
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,321
      Helping Hand
      Rank: Community Hero

      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.

    • #192775
      Participant
      Topics: 5
      Replies: 106
      Points: 273
      Helping Hand
      Rank: Contributor

      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.

    • #192871
      Participant
      Topics: 1
      Replies: 4
      Points: 20
      Rank: Member

      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

      }

      }

      }

       

    • #192874
      Participant
      Topics: 5
      Replies: 106
      Points: 273
      Helping Hand
      Rank: Contributor

      Would this match the need?

      edit from import-certificate to import-csv

    • #192877
      Participant
      Topics: 1
      Replies: 4
      Points: 20
      Rank: Member

      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: (:) [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: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

    • #192898
      Participant
      Topics: 1
      Replies: 4
      Points: 20
      Rank: Member

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

       

    • #192958
      Participant
      Topics: 5
      Replies: 330
      Points: 527
      Helping Hand
      Rank: Major Contributor
    • #192976
      Participant
      Topics: 1
      Replies: 4
      Points: 20
      Rank: Member

      Thank you . This is exactly what i was looking for

       

    • #193075
      Participant
      Topics: 5
      Replies: 106
      Points: 273
      Helping Hand
      Rank: Contributor

      tab completion error 😀

Viewing 9 reply threads
  • The topic ‘Move file listed on csv file’ is closed to new replies.