PowerShell a method for moving a specified file in a directory (not all files) _powershell

Source: Internet
Author: User

Small knitting in doing a small function, encountered a function, is to a directory of specified conditions in the file, moved to another directory. This is the demand, and then we will analyze how to achieve it.

First get a table of contents project, the first time can think of get-childitem, but we used too much, this small series want to change a pattern, we use Get-item, and then use wildcard characters to include all the subprojects. Of course, if you need to specify a file that matches the filename, you can use the matching rule directly here.

Then from the selected subprojects, filter the files in. This is also a very common function, that is to determine whether the Psiscontainer property is $false.

Finally, the filtered results are then move to another directory, of course, the use of Move-item this cmd-let.

So the final code is as follows:

Copy Code code as follows:

Get-item < path 1>\* | Where-object {$_. Psiscontainer-eq $false} | Move-item-destination < paths to another directory >

If your needs are slightly out of the small demo, but with this template, it should be easy to change the way you want it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.