Results 1 to 5 of 5

Thread: FileCopy (VB6)

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileCopy (VB6)

    With my code below I have added a couple of lines referencing the kill statement.

    I think It will cause me problems if it is executed.

    <pre> If Right$(FN, 3) = "jpg" Then
    FileCopy SrcFolder & File1.List(N), JpgFolder & FN
    Kill SrcFolder & File1.List(N)
    End If

    If Right$(FN, 3) = "pdf" Then
    FileCopy SrcFolder & File1.List(N), PdfFolder & FN
    Kill SrcFolder & File1.List(N)
    End If</pre>


    I know whats going to happen, the code will Filecopy and then delete (Kill) everything else in the list, regardless whether JPG or PDF.
    Is there anything extra to add to the two lines of code or a replacement for FileCopy ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    I don't see why this would delete everything else in the list, but since you are copying a file and then deleting the original, you can replace the two lines

    FileCopy SrcFolder & File1.List(N), JpgFolder & FN
    Kill SrcFolder & File1.List(N)

    by one line that renames the file:

    Name SrcFolder & File1.List(N) As JpgFolder & FN

    If the new name includes a different path, you are actually moving it.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Hans
    Your updated one liner works fine.
    I already have numerous archived files which will with the new line of code causes a "File already exists" error.
    I know why, and it's easy to sort. It just means a little time sorting the duplicates.

    With my previous code, ie the Kill statement, just clarify if I'm correct.
    All the files are archived systematically and by file name.
    To cut it short, an archived folder will contain both PDF and JPG files, ie:
    Folder Name = 12345
    12345-EST.pdf
    12345-INT.pdf
    12345-01.jpg
    12345-02.jpg
    12345-03.jpg

    When I want to un-Archive them for some reason, I am using the following code which works ok::

    <pre> For N = 0 To File1.ListCount - 1
    If File1.Selected(N) Then
    FN = File1.List(N)
    End If

    If Right$(FN, 3) = "jpg" Then
    FileCopy SrcFolder & File1.List(N), JpgFolder & FN
    End If

    If Right$(FN, 3) = "pdf" Then
    FileCopy SrcFolder & File1.List(N), PdfFolder & FN
    End If

    Next N</pre>


    But leaves a copy in the source folder because of using "FileCopy"
    So in fact If I select all files in the list, both file formats, they are extracted back to the correct originating folder:
    JpgFolder = L:MMPDFIMAGE & PdfFolder = L:MMPDFESTPDF

    When I include the Kill line after each "FileCopy" statement, is the Kill only dealing with Each FileCopy, ie JPG or PDF ?
    ************************************************** ************************************************** *******************************

    Hang on, silly me, If I have already extracted items from the list which were selected, then one Kill statement should really be suffice before
    clearing the list !! Am I correct ?

    Air Code:

    <pre> For N = 0 To File1.ListCount - 1
    If File1.Selected(N) Then
    FN = File1.List(N)
    End if

    If Right$(FN, 3) = "jpg" Then
    FileCopy SrcFolder & File1.List(N), JpgFolder & FN
    End If

    If Right$(FN, 3) = "pdf" Then
    FileCopy SrcFolder & File1.List(N), PdfFolder & FN
    End If
    Next N</pre>




    <pre> For N = 0 To File1.Selected
    Kill (N)
    Next N</pre>


    Or am I complicating things again ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    Sorry, the code

    For N = 0 To File1.Selected
    Kill (N)
    Next N

    is nonsense. File1.Selected is not a number, and the Kill instruction tries to delete the number N. Mathematicians won't appreciate you killing off numbers.

    If you want to delete the selected items, use

    For N = 0 to File1.ListCount - 1
    If File1.Selected(N) Then
    Kill SrcFolder & File1.List(N)
    End If
    Next N

    If you want to delete ALL files listed in the list box, use:

    For N = 0 to File1.ListCount - 1
    Kill SrcFolder & File1.List(N)
    Next N

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>

    I told you it was Air Code !!

    Better stick to my Air Guitar instead eh ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •