Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: Moving files based on filesize

Reply
 
Old 11-11-2008   #1 (permalink)
RickB


 
 

Re: Moving files based on filesize

On Nov 11, 10:16*am, "kjime...@xxxxxx" <kjime...@xxxxxx> wrote:
Quote:

> Good morning,
>
> I am trying to write a script that will move files smaller than a
> certain file size. We have an issue where we are faxing corrupt faxes
> out at my job, and all corrupt faxes are great than 3MB so I am
> looking to write a script that will send all valid files to a working
> directory, and not move invalid faxes. Here is the test script I wrote
> to move files under 3KB:
>
> $source="C:\Test\"
> $destination="C:\Test2\"
> $size=0.3
> cd $source
> $a=get-childitem -recurse
> foreach ($x in $a)
> {
> $y=($x | measure-object -property length -sum).sum/1KB
> if ($y -lt $size)
> {
> $x | move-item $destination -force
>
> }
> }
>
> I receive the following error:
>
> Move-Item : The input object cannot be bound to any parameters for the
> command either because the command does not take pipeline
> input or the input and its properties do not match any of the
> parameters that take pipeline input.
> At line:11 char:15
> + $x | move-item <<<< *$destination -force
>
> Can I just put move-item $destination in this case?
Does this work for you?

cd "C:\Test\"
$dest = "C:\Test2\"
$size = 0.3
Get-ChildItem -rec|
?{$_.Length -lt $size -and !$_.PSIsContainer}|
%{move-item -lit $_ -dest $dest}

My System SpecsSystem Spec
Old 11-11-2008   #2 (permalink)
RickB


 
 

Re: Moving files based on filesize

On Nov 11, 2:11*pm, "kjime...@xxxxxx" <kjime...@xxxxxx> wrote:
Quote:

> On Nov 11, 12:44*pm, RickB <rbiel...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > On Nov 11, 10:16*am, "kjime...@xxxxxx" <kjime...@xxxxxx> wrote:
>
Quote:
Quote:

> > > Good morning,
>
Quote:
Quote:

> > > I am trying to write a script that will move files smaller than a
> > > certain file size. We have an issue where we are faxing corrupt faxes
> > > out at my job, and all corrupt faxes are great than 3MB so I am
> > > looking to write a script that will send all valid files to a working
> > > directory, and not move invalid faxes. Here is the test script I wrote
> > > to move files under 3KB:
>
Quote:
Quote:

> > > $source="C:\Test\"
> > > $destination="C:\Test2\"
> > > $size=0.3
> > > cd $source
> > > $a=get-childitem -recurse
> > > foreach ($x in $a)
> > > {
> > > $y=($x | measure-object -property length -sum).sum/1KB
> > > if ($y -lt $size)
> > > {
> > > $x | move-item $destination -force
>
Quote:
Quote:

> > > }
> > > }
>
Quote:
Quote:

> > > I receive the following error:
>
Quote:
Quote:

> > > Move-Item : The input object cannot be bound to any parameters for the
> > > command either because the command does not take pipeline
> > > input or the input and its properties do not match any of the
> > > parameters that take pipeline input.
> > > At line:11 char:15
> > > + $x | move-item <<<< *$destination -force
>
Quote:
Quote:

> > > Can I just put move-item $destination in this case?
>
Quote:

> > Does this work for you?
>
Quote:

> > cd * * *"C:\Test\"
> > $dest = "C:\Test2\"
> > $size = 0.3
> > Get-ChildItem -rec|
> > * ?{$_.Length -lt $size -and !$_.PSIsContainer}|
> > * %{move-item -lit $_ -dest $dest}
>
> That does not give me an error, but it does not move files either.- Hide quoted text -
>
> - Show quoted text -
Oops,

%{move-item -lit $_.FullName -dest $dest}
My System SpecsSystem Spec
Old 11-11-2008   #3 (permalink)
RickB


 
 

Re: Moving files based on filesize

On Nov 11, 2:41*pm, RickB <rbiel...@xxxxxx> wrote:
Quote:

> On Nov 11, 2:11*pm, "kjime...@xxxxxx" <kjime...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > On Nov 11, 12:44*pm, RickB <rbiel...@xxxxxx> wrote:
>
Quote:
Quote:

> > > On Nov 11, 10:16*am, "kjime...@xxxxxx" <kjime...@xxxxxx> wrote:
>
Quote:
Quote:

> > > > Good morning,
>
Quote:
Quote:

> > > > I am trying to write a script that will move files smaller than a
> > > > certain file size. We have an issue where we are faxing corrupt faxes
> > > > out at my job, and all corrupt faxes are great than 3MB so I am
> > > > looking to write a script that will send all valid files to a working
> > > > directory, and not move invalid faxes. Here is the test script I wrote
> > > > to move files under 3KB:
>
Quote:
Quote:

> > > > $source="C:\Test\"
> > > > $destination="C:\Test2\"
> > > > $size=0.3
> > > > cd $source
> > > > $a=get-childitem -recurse
> > > > foreach ($x in $a)
> > > > {
> > > > $y=($x | measure-object -property length -sum).sum/1KB
> > > > if ($y -lt $size)
> > > > {
> > > > $x | move-item $destination -force
>
Quote:
Quote:

> > > > }
> > > > }
>
Quote:
Quote:

> > > > I receive the following error:
>
Quote:
Quote:

> > > > Move-Item : The input object cannot be bound to any parameters for the
> > > > command either because the command does not take pipeline
> > > > input or the input and its properties do not match any of the
> > > > parameters that take pipeline input.
> > > > At line:11 char:15
> > > > + $x | move-item <<<< *$destination -force
>
Quote:
Quote:

> > > > Can I just put move-item $destination in this case?
>
Quote:
Quote:

> > > Does this work for you?
>
Quote:
Quote:

> > > cd * * *"C:\Test\"
> > > $dest = "C:\Test2\"
> > > $size = 0.3
> > > Get-ChildItem -rec|
> > > * ?{$_.Length -lt $size -and !$_.PSIsContainer}|
> > > * %{move-item -lit $_ -dest $dest}
>
Quote:

> > That does not give me an error, but it does not move files either.- Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> Oops,
>
> * *%{move-item -lit $_.FullName -dest $dest}
>
> - Show quoted text -
Or, now that I think about it, just ...|move-item -dest $dest
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Delete files based on dup names PowerShell
Moving files from one directory to another based on the file namecontains specified string by using vbscript VB Script
Moving folders (including files) based to folder name PowerShell
Re: Moving e-mails from XP to Vista based laptop. Vista mail
CD Burning Filesize Swap? Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46