Page 1 of 2
exclude specific file
Posted: Tue Jul 03, 2018 10:05 am
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
Re: exclude specific file
Posted: Tue Jul 03, 2018 10:15 am
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
Re: exclude specific file
Posted: Tue Jul 03, 2018 10:45 am
by sshree43
sorry not working and not moving any file
Re: exclude specific file
Posted: Tue Jul 03, 2018 10:48 am
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
Re: exclude specific file
Posted: Tue Jul 03, 2018 10:54 am
by sshree43
no still not moving
Re: exclude specific file
Posted: Tue Jul 03, 2018 11:03 am
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]
Re: exclude specific file
Posted: Tue Jul 03, 2018 11:17 am
by sshree43
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
Re: exclude specific file
Posted: Tue Jul 03, 2018 11:25 am
by jvierra
You can't. It requires a completely different coding approach. Just write two statements.
Re: exclude specific file
Posted: Tue Jul 03, 2018 11:34 am
by sshree43
How can i give helpful and correct solution remarks
Re: exclude specific file
Posted: Tue Jul 03, 2018 11:41 am
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.