Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Card Reader (A2k)

    We use a flash compact card for imaging on various estimating systems.

    The card itself, creates its own folders, the names of which are not important.
    What I can say, is it will create the folders with different incremented names, ie
    ImgFolder5619
    ImgFolder5620 etc etc.

    In the workshop I have put an old camera, not high spec but adequate for parts found damaged on stripping.
    The additional parts are requested and the flash card given to the estimator for updating.
    What I would like to do is to attach another card reader to the work shop, when additional images are taken, not hand the card in but.
    The workshop staff put the card in the reader, press one button, the images saved to a default location and then delete what evers on the card.

    Most of the code I can sort my self, but the code I would need help on is as follows.

    1.Search thru all folders regardless of the folder name and find any Jpg's, the drive would usually be E:
    2.Delete all folders and Jpg's once saved to the default location.

    All other code I probably have.

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

    Re: Card Reader (A2k)

    I don't have enought time to work out the details, but you might look into Application.FileSearch:

    Sub TestSearch()
    Dim i As Long
    With Application.FileSearch
    .NewSearch
    .LookIn = "E:"
    .SearchSubFolders = True
    .FileType = msoFileTypeAllFiles
    .FileName = "*.jpg"
    .Execute
    For i = .FoundFiles.Count To 1 Step -1
    Debug.Print .FoundFiles(i)
    Next i
    End Sub

    This code requires a reference to the Microsoft Office n.0 Object Library (n = 8 for Office 97, n = 9 for Office 2000, n = 10 for Office XP etc.)

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

    Re: Card Reader (A2k)

    Thanks Hans
    This is very useful, I'm sure I can implement this from here.

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Card Reader (A2k)

    Hi Dave

    Take a look at File Catalog Utility at Version 1.0 - By Steve Nyberg 1999 (http://www.stevenyberg.com)
    to handle:

    1.Search thru all folders regardless of the folder name and find any Jpg's, the drive would usually be E:

    Once these files are cataloged, you could write code to delete them.

    HTH John

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

    Re: Card Reader (A2k)

    Thanks John, some very useful stuff here.

    In my case, I don't really want any kind of user intervention, just a script behind one button to perform all the task:

    Find, Export, Delete, Start from an empty card.

    I know I'll have to be careful with the code, so trapping any unneccessary actions.

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

    Re: Card Reader (A2k)

    Ok, I've got this far with an error on the following line:

    FileCopy "strSourceFolder", strMainFolder
    Error 53, File Not Found

    C:Workshop path is only used here as an example which I will change when I get the code running correctly to E:.
    The machine I am writing on does not have the card reader attached.
    I have created "Workshop" on my C: drive and put 12 images in there for testing.
    The .FoundFiles returns the correct number of Images (12)

    <pre>Private Sub Command0_Click()
    Dim i As Long
    Dim strMainFolder As String
    Dim strSourceFolder As String

    strMainFolder = "L:WorkShop"
    strSourceFolder = "C:WorkShop"

    ' Check if WorkShop folder exists
    If Dir(strMainFolder, vbDirectory) = "" Then
    MsgBox "Folder Does Not Exist" & vbCrLf & "Creating Folder Now", "Make Directory"
    MkDir strMainFolder
    End If

    'Check if source folder exists
    If Dir(strSourceFolder, vbDirectory) = "" Then
    MsgBox "No Card !!" & vbCrLf & "Please Insert Image Card Before Proceeding", "Card Reader Error"
    DoCmd.Close acForm, Me.Name
    End If

    With Application.FileSearch
    .NewSearch
    .LookIn = "C:WorkShop"
    .SearchSubFolders = True
    .FileType = msoFileTypeAllFiles
    .FileName = "*.jpg"
    .Execute
    For i = .FoundFiles.Count To 1 Step -1

    'Copy *.Jpg Images from C:Workshop to L:Workshop
    FileCopy "strSourceFolder", strMainFolder

    Next i
    End With

    Exit Sub
    End Sub</pre>


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

    Re: Card Reader (A2k)

    Look at this instruction:

    FileCopy "strSourceFolder", strMainFolder

    Both strSourceFolder and strMainFolder are string variables, yet you have enclosed the former in quotes, making FileCopy look for something literally called "strSourceFolder" instead of getting the value of the variable. Moreover, you can't use CopyFile to copy a folder; you would need to loop through all files in the source folder and copy them one by one:

    Dim strFile As String
    strFile = Dir(strSourceFolder & "*.jpg")
    Do While strFile <> ""
    FileCopy strSourceFolder & strFile, strMainFolder & strFile
    strFile = Dir
    Loop

    or set a reference to the Microsoft Scripting Runtime and use FileSystemObject. It has a method CopyFolder.

    Dim fso As New Scripting.FileSystemObject

    If fso.FolderExists(strMainFolder) = False Then
    fso.CreateFolder strMainFolder
    End If

    If fso.FolderExists(strSourceFolder) = False Then
    MsgBox "No card ..."
    Exit Sub
    End If

    fso.CopyFolder strSourceFolder, strMainFolder
    Set fso = Nothing

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

    Re: Card Reader (A2k)

    Hans
    I understand your code but I am now totally cofused.
    Your first statement !! I have broken down and inserted where "I" think it should go.
    I'm obviously wrong.
    (It might be the fact I had one too many beers <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> last night.

    <pre>Private Sub Command0_Click()
    Dim i As Long
    Dim strMainFolder As String
    Dim strSourceFolder As String
    Dim strFile As String

    strMainFolder = "L:WorkShop"
    strSourceFolder = "C:WorkShop"
    strFile = Dir(strSourceFolder & "*.jpg")

    ' Check if WorkShop folder exists
    If Dir(strMainFolder, vbDirectory) = "" Then
    MsgBox "Folder Does Not Exist" & vbCrLf & "Creating Folder Now", "Make Directory"
    MkDir strMainFolder
    End If

    'Check if source folder exists
    If Dir(strSourceFolder, vbDirectory) = "" Then
    MsgBox "No Card !!" & vbCrLf & "Please Insert Image Card Before Proceeding", "Card Reader Error"
    DoCmd.Close acForm, Me.Name
    End If


    With Application.FileSearch
    .NewSearch
    .LookIn = "C:WorkShop"
    .SearchSubFolders = True
    .FileType = msoFileTypeAllFiles
    .FileName = "*.jpg"
    .Execute
    For i = .FoundFiles.Count To 1 Step -1

    'Copy *.Jpg Images from C:Workshop to L:Workshop

    Do While strFile <> ""
    FileCopy strSourceFolder & strFile, strMainFolder & strFile
    strFile = Dir
    Loop

    Next i
    End With

    Exit Sub
    End Sub</pre>


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

    Re: Card Reader (A2k)

    Dave,

    Two different methods are getting mixed up now: using FileSearch and using Dir to loop through a folder. It won't be difficult to fix it (I think), but before doing that, we need to get something straight.

    If I understood the first post in this thread correctly, you are going to search a source folder for .jpg files; they are stored in subfolders with names such as "ImgFolder5619".
    Should all found .jpg files be copied to the target (main) folder itself, regardless of the subfolder they are in, or should the subfolders be copied and the .jpg's be copied to the subfolders?

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

    Re: Card Reader (A2k)

    Hans

    You're right about being mixed up.
    It's me I'm afraid, going off in tangents again.!!!
    Here's the process of events.

    Card reader on machine.
    User inserts card.
    Press's export button.
    Code firstly checks if Source exists, (E if he has actually inserted the card or not.
    If not, warn him and get out.

    Code checks if destination exists, if not mkDir "L:WorkShop"

    Card is in, code searches thru all folders and captures the jpgs.
    All jpgs are exported to "L:WorkShop" (network drive)

    Then all folders and images deleted from source E: so card is empty when removed from reader.

    The destination drive doesn't require the folders exported as well.
    When the estimator in the office has taken the pics, she will delete them anyway.

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

    Re: Card Reader (A2k)

    OK, that shouldn't be too hard. I'll get back to you later.

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

    Re: Card Reader (A2k)

    Dave,

    Here is code that uses FileSystemObject (attached). To use it, you must set a reference to Microsoft Scripting Host in Tools | References...

    The source and target path are defined as constants at the top of the code; they must be copied to the top of your module, as well as the declaration of fso. Adapt the paths as needed.

    Warning: This code deletes all subfolders and files in the subfolders of the source path, so it can be very dangerous if the wrong path is supplied. Before testing this code, make sure that you have backups. I recommend that you set a breakpoint in the code and single step through it the first time to verify that it doesn't wreak havoc.
    Attached Files Attached Files

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

    Re: Card Reader (A2k)

    Thanks again Hans.
    The coding is interesting, and I see some resemblences to my original, which is re-assuring.
    I will be very careful and intend to add a couple of bells and whistles hopefully to trap any problems that can arise.
    Fortunately, the machine this will reside on is not too important.

    I will possibly try to trap in the source folder for, C: & L: So as not to cause any errors in here.
    Any other Drives I can remove the mapping.

    If you see any other problems that can occur, please let me know.

    Here goes, wish me luck !!

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

    Re: Card Reader (A2k)

    Just in case, here is a version that is more like the original. It doesn't remove folders, though, only files.
    Attached Files Attached Files

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

    Re: Card Reader (A2k)

    Phew

    You put that together quick.
    Hopefully, I won't be staring at a blank screen tomorrow ! <img src=/S/hiding.gif border=0 alt=hiding width=70 height=24> , I would be in trouble wouldn't I <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

Page 1 of 2 12 LastLast

Posting Permissions

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