Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:00:47+00:00 2026-06-17T08:00:47+00:00

$Basically what I’m trying to do is: I’m pulling information from a .csv spreadsheet

  • 0

$Basically what I’m trying to do is:

I’m pulling information from a .csv spreadsheet that contains a list of files that I need. The problem is, the directory they are in contains 16,000+ files! I only need around 4600 of them (as the spreadsheet column only contains that many). I’ve actually gotten all that part of the code figured out… but where I’m running into issues is when it gets to the “Copy-Item” portion of my code. It runs fine until it hits files that have brackets as part of the filename, so of course it throws errors and doesn’t give me what I need. How can I fix this? Mind you, the files needing/being copied CAN’T be renamed. I’m not sure how to use “-LiteralPath” here, if that’s a solution. 🙁 Here’s my code below:

$Directory = gci D:\Documents\15075_32\
$Destination = "D:\CleanReview"
$ReviewSheet = import-csv 'C:\Users\7cm\Desktop\Internal Review - Emails Removed per Attorney Request.csv'
$BaseItem = foreach($li in $ReviewSheet){$li.Base}
foreach($File in $Directory){
    $File.BaseName
foreach($Item in $BaseItem){
    if($Item -like $File.BaseName){
        $Item
            Copy-Item $File.FullName $Destination -Force
}
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:00:48+00:00Added an answer on June 17, 2026 at 8:00 am

    Ok… after MUCH research through Google, I was able to find that even with the corrections in V3 of PS, and even with the -LiteralPath operator, it was still interpreting the filenames with wildcards within the copy. Through much trial an error on my own, I found that the operator within the IF statement was causing this. Even when -LiteralPath is used, it’s within the IF statement and is forgotten when the criteria is true. So in order to combat this and then also make it read the filenames without wildcard interpretation I had to switch my -like to an -eq since -eq doesn’t support wildcards. The next problem I ran into with this though was PS kept reporting it couldn’t find the files as it was looking in the C drive! It would still do this even though I’ve declared the directory and even after I would use the declaration in shorthand within the copy command! PS seems to be very tempermental with this, and as a result I found that literally spelling it out completely for the script is what will acheive the results I needed! So to review, I’m taking a csv and reading one of the columns as that column is a list of filenames without extensions. I am comparing that list to a directory list, and when the column list of names matches the basenames within the directory… I needed it to copy those directory files to another folder on the D drive. Here is my working code! Thanks to Keith Hill (above), I started looking at it a little differently! Thanks for your help!

    $Directory = gci -LiteralPath D:\Documents\15075_32\
    $Destination = "D:\CleanReview\"
    $ReviewSheet = import-csv 'C:\Users\7cm\Desktop\Internal Review - Emails Removed per Attorney Request.csv'
    $BaseItem = foreach($li in $ReviewSheet){$li.Base}
    foreach($File in $Directory){
    foreach($Item in $BaseItem){
        if($Item -eq $File.BaseName){
            $Item
                Copy-Item -LiteralPath D:\Documents\15075_32\$File -Destination $Destination -Force
    }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I am creating a dynamic google map that pulls information from the database,
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, from the form that I made I send customer_name and with this code
Basically what i am trying to do here is to read from the table
Basically I need to verify that a certain program is not running before installation.
Basically, I have a function that exports data to a csv format for excel...
Basically I need to get older version of a file in the repository without
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically, I have a list of delivery checkboxes one for deliver to this address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.