exclude specific file

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

exclude specific file

Post by sshree43 » Tue Jul 03, 2018 10:05 am

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

User avatar
jvierra
Posts: 13470
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: exclude specific file

Post by jvierra » Tue Jul 03, 2018 10:15 am

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 » Tue Jul 03, 2018 10:45 am

sorry not working and not moving any file

User avatar
jvierra
Posts: 13470
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: exclude specific file

Post by jvierra » Tue Jul 03, 2018 10:48 am

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 » Tue Jul 03, 2018 10:54 am

no still not moving

User avatar
jvierra
Posts: 13470
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: exclude specific file

Post by jvierra » Tue Jul 03, 2018 11:03 am

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 » Tue Jul 03, 2018 11:17 am

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

User avatar
jvierra
Posts: 13470
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: exclude specific file

Post by jvierra » Tue Jul 03, 2018 11:25 am

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 » Tue Jul 03, 2018 11:34 am

How can i give helpful and correct solution remarks

User avatar
jvierra
Posts: 13470
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: exclude specific file

Post by jvierra » Tue Jul 03, 2018 11:41 am

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