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.
User avatar
sshree43
Posts: 33
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Wed Jun 27, 2018 11:57 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: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

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
Joined: Wed Jun 27, 2018 11:57 am

Re: exclude specific file

Post by sshree43 »

sorry not working and not moving any file

jvierra
Posts: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

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
Joined: Wed Jun 27, 2018 11:57 am

Re: exclude specific file

Post by sshree43 »

no still not moving

jvierra
Posts: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

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
Joined: Wed Jun 27, 2018 11:57 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: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

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
Joined: Wed Jun 27, 2018 11:57 am

Re: exclude specific file

Post by sshree43 »

How can i give helpful and correct solution remarks

jvierra
Posts: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

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.

Locked