We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Count files & move them!

plenahan
plenahan asked
on
Medium Priority
195 Views
Last Modified: 2010-04-23
I have a program that splits tif files wonderfully but, my concern is this. I have a folder called c:\shipping with  a lot of tif files numbered from 001.tif to whatever, like 0150.tif.
Example
001.tif 9kb
002.tif 27kb
003.tif 26kb
004.tif 27kb
005.tif 22kb
006.tif 9kb
007.tif 27kb
008.tif 15kb
009.tif 10kb
010.tif 20kb
011.tif 10kb
012.tif 16kb

First we know if the file is <= 10 kb this is a blank page that seperates one invoice from another.
What I need is the first page of every invoice moved to c:\test
Must read each tif in numerical order.
The result would be file# 002.tif, 007.tif, 010.tif, 012.tif and  so on to the end.
Needed to be coded in vb.net and this is urgent.

Comment
Watch Question

Commented:
'CDCOP
        Dim lngDirSize As Long
        Dim objFileInfo As System.IO.FileInfo
        Dim objDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\shipping")
        Dim Movenext As Boolean

        For Each objFileInfo In objDir.GetFiles()
            lngDirSize = objFileInfo.Length

            If Movenext = True Then
                System.IO.File.Move(objFileInfo.FullName, "c:\test\" & objFileInfo.Name)
            End If

            If lngDirSize <= 10000 Then
                Movenext = True
            Else
                Movenext = False
            End If

        Next

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
just gonna re-arrange  cdcop code to make it right..

CDCOP
        Dim lngDirSize As Long
        Dim objFileInfo As System.IO.FileInfo
        Dim objDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\shipping")
        Dim Movenext As Boolean

        For Each objFileInfo In objDir.GetFiles()
            lngDirSize = objFileInfo.Length

            If lngDirSize <= 10000 Then
                Movenext = True
            Else
                Movenext = False
            End If

            If Movenext = True Then
                System.IO.File.Move(objFileInfo.FullName, "c:\test\" & objFileInfo.Name)
            End If
         Next

Commented:
There is nothing wrong with my code.

So please explain why YOU think it is 'wrong'

Commented:
The way I read the author's text, your rearranging of my code is actually wrong.

Files <= 10k are a seperator page
The NEXT page starts the invoice and 'What I need is the first page of every invoice moved to c:\test'
So that page should be moved to the folder, not the blank seperator pages.

Commented:
sorry.. about my lack of explanation.. and my mind was moving to fast that i forgot  to ask plenahan, if a separator page is default as start of your directory(sample 1)  or sometimes it starts with the first page(sample 2)?

sample1:
001.tif <10kb--> separator page /(starting file)
002.tif >10k --> 1st page/next page

Sample2:
001.tif >10kb--> 1st Page /(starting file)
.....
00x.tif  <10k --> separator page
00y.tif >10kb--> nextpage

and after re-checking what I did.. i also forgot to add something.. here i'm really sorry...
Here updated and working
       
       Dim lngDirSize As Long
        Dim objFileInfo As System.IO.FileInfo
        Dim objDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\shipping")
        Dim Movenext As Boolean= False
        Dim FirstPage As Boolean= False

        For Each objFileInfo In objDir.GetFiles()
            lngDirSize = objFileInfo.Length

            If lngDirSize <= 10000 Then
                Movenext = True
            Else
               
            if Movenext=True then
             FirstPage=True
            else
            FirstPage=False
            End if
            Movenext = False
               
            End If

            If Movenext = False and FirstPage= True Then
                System.IO.File.Move(objFileInfo.FullName, "c:\test\" & objFileInfo.Name)
            End If
         Next

and again I'm totally sorry cdcop...

Commented:
So what makes this any different than my code?

Author

Commented:
I'm checking the code today and will let you know my answer soon. :)

Commented:
i was already thinking about sample2 when I made the post...

Author

Commented:
I ran the test on 150 pages and it did what I asked for. Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!   :)
Only get the first page of every invoice. thanks

Your the man cdcop.

Commented:
No problem.

Thanks for points and grade.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.