exclude specific file

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

exclude specific file

Post by sshree43 »

Hi Expert,

I am trying to move the file to archive except for 2 files and just want to copy this files to archive..
but getting the error message input parameter is invalid

Code: Select all

$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate'
$destdir   = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir |
Move-Item $sourcedir $destdir[b] -Exclude "ven late sapping.xlsx","Qk PU waisting.xlsx"[/b] 
files are
ven late sapping.xlsx
Qk PU waisting.xlsx
ven late sapping_1.xlsx
Qk PU waisting_1.xlsx

thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: exclude specific file

Post by jvierra »

Try it like this:

Code: Select all

$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir   = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
    Move-Item  =Destination $destdir 
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: exclude specific file

Post by sshree43 »

sorry not working and not moving any file
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: exclude specific file

Post by jvierra »

Sorry. I forgot the parameter name:

Code: Select all

$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir   = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
    Move-Item  =Destination $destdir 
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: exclude specific file

Post by sshree43 »

no still not moving
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: exclude specific file

Post by jvierra »

Perhaps your selection criteria is wrong. Do you get an output from the selection part?

]b]$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'[/b]
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: exclude specific file

Post by sshree43 »

Code: Select all

*'
i removed this from the source directory due to giving an error with your first solution

It's working now moving all files the except two files..How to copy that two files to destination directory in the same statement

I tried with pipe to your statement but not working

Code: Select all

$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir   = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
    Move-Item  =Destination $destdir |
Copy-Item $sourcedir -Destination $destdir -Recurse
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: exclude specific file

Post by jvierra »

You can't. It requires a completely different coding approach. Just write two statements.
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: exclude specific file

Post by sshree43 »

How can i give helpful and correct solution remarks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: exclude specific file

Post by jvierra »

sshree43 wrote: Tue Jul 03, 2018 11:34 am How can i give helpful and correct solution remarks
I don't understand this question.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked