locked
Copy file to Folder using Powershell.. RRS feed

  • Question

  • Hi,

    I have a Problem. I have almost 50000 files (.txt, .pdf, . csv)etc . All the files has specific name like ( Customer.txt, car.txt, Customer.pdf). And i have also 50000 folder named like file name (Customer, Car, House) etc. Now how can i copy those files to specific folder eg (Customer.txt & pdf to Customer folder ) and (Car.txt &.pdf to Car folder) and so on. is any powershell command to copy all the files to specific folder compare to file name.  If anyone can help then it would be bit easier.

    Thanks to all

    AArif Chowdhury

    Monday, February 11, 2019 10:56 AM

Answers

  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, February 28, 2019 2:37 PM

All replies

  • A filename has a "Basename"  The basename is what you need to use to match tot he folder.

    Get-ChildItem | select basename, fullname


    \_(ツ)_/

    Monday, February 11, 2019 12:00 PM
  • Hi,

    For example:

    get-childitem -Path C:\0212\ -File | % {Copy-Item $_.FullName -Destination "c:\0212\$($_.BaseName)"}

    You need to change the file path to meet your need.

    Best Regards,

    Lee


    Just do it.

    Tuesday, February 12, 2019 5:55 AM
  • Hi,

    For example:

    get-childitem -Path C:\0212\ -File | % {Copy-Item $_.FullName -Destination "c:\0212\$($_.BaseName)"}

    You need to change the file path to meet your need.

    Best Regards,

    Lee


    Just do it.

    Why must you repeat what others have posted?  It seems a bit odd.


    \_(ツ)_/

    Tuesday, February 12, 2019 6:40 AM
  • Hi Lee,

    Thanks, It works.

    Arif

    Tuesday, February 12, 2019 7:21 AM
  • Hi Lee,

    Thanks, It works.

    Arif

    And you learned nothing but how to get a free script. Good for you.


    \_(ツ)_/

    Tuesday, February 12, 2019 7:23 AM
  • Hi Jrv,

    I'm sorry to annoy you. Your reply really has given the key to solve the problem. If the OP doesn't understand PowerShell and just wants to solve the problem through it, I don't think he can solve the problem based on your reply. 

    I understand the rules of the forum reply, I am sorry for my behavior.

    Best Regards,

    Lee


    Just do it.

    Wednesday, February 13, 2019 2:47 AM
  • Hi AArif,

    Please mark Jrv's answer to help other community members find the helpful reply quickly.

    Best Regards,

    Lee


    Just do it.

    Wednesday, February 13, 2019 2:49 AM
  • Hi Jrv,

    I'm sorry to annoy you. Your reply really has given the key to solve the problem. If the OP doesn't understand PowerShell and just wants to solve the problem through it, I don't think he can solve the problem based on your reply. 

    I understand the rules of the forum reply, I am sorry for my behavior.

    Best Regards,

    Lee


    Just do it.

    No problem Lee.  Since you seem to have no practical experience in computing I can suggest that you spend more time thinking about questions.  The best experience comes from working as a tech in a sizable network.  Without that you can easily miss some things.  On the better side, sometimes you find good articles and see good solutions.  You don't need to restate what others post.  Rely on your own smarts and provide help based on what you have experience with. 

    These forums should not be about points.  I post because I want to help point others to better ways to use PowerShell.   I almost never look at the points or care about having the chosen answer.


    \_(ツ)_/


    • Edited by jrv Wednesday, February 13, 2019 3:03 AM
    Wednesday, February 13, 2019 3:01 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, February 28, 2019 2:37 PM