DBF to CSV in batch: how to do?

Page 1 of 2 12 LastLast

  1. Posts : 9
    Windows 7
       #1

    DBF to CSV in batch: how to do?


    Dear Community,
    I need to convert every minute (1 minute) a file generate in format DBF into the CSV format. I looked around some script, I found one script in Python but unfortunately it doesn't work.

    Can you help me?


    Cheers,
      My Computer


  2. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #2

    sev7en said:
    Dear Community,
    I need to convert every minute (1 minute) a file generate in format DBF into the CSV format. I looked around some script, I found one script in Python but unfortunately it doesn't work.

    Can you help me?


    Cheers,
    What program does create the DBF file each minute?
      My Computer


  3. Posts : 9
    Windows 7
    Thread Starter
       #3

    Good afternoon,
    thanks for the prompt reply. It is a internal monitor application for enviromental data mining. I have uploaded it here: https://www.m-e-d-i-a-f-i-r-e.com/?a2nn9ihat6zs90k


    Cheers,
      My Computer


  4. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #4

    Can't you simply adjust the "monitor application" so it output to CSV?
    Otherwise I don't have a solution.
      My Computer


  5. Posts : 9
    Windows 7
    Thread Starter
       #5

    Hi, no sorry I cannot...
      My Computer


  6. Posts : 2,468
    Windows 7 Ultimate x64
       #6

    I think Excel can deal with both formats. Do you have it avaiable?
    Try opening with Excel, and saving in CSV afterwards, see if the resulting file satisfies your needs.
      My Computer


  7. Posts : 9
    Windows 7
    Thread Starter
       #7

    Good evening,
    yes, Excel is able to handle it but I have to do that via command line, as it's a trigged operation (via file batch).


    Regards,
      My Computer


  8. Posts : 2,468
    Windows 7 Ultimate x64
       #8

    Great. Then, it's just a matter of scripting Excel to do the job automatically. For example, you may use VBScript to instruct Excel to load the dbf, then re-save it as csv:

    Code:
    Const xlCSV = 6
    
    'Open Excel and load dbf within it
    Set objExcel = CreateObject("Excel.Application")
    objExcel.DisplayAlerts = FALSE
    objExcel.Visible = FALSE
    Set objWorkbook = objExcel.Workbooks.Open("C:\temp\test.dbf")
    
    'Just save it without any modification, chosing CSV as format
    objWorkbook.SaveAs "C:\temp\test.csv", xlCSV
    objWorkbook.Close
    
    'Close Excel and quit
    objExcel.Quit
    WScript.Quit
    Save this as a .vbs file. It can be called directly from command line afterwards, included in a .bat file, scheduled task or whatever.

    Be sure to fully test it on real sample data, I've just played with it a little. While I think it's a reasonably good approach, it's definitely not production quality. For instance, it lacks error handling . But you may be able to tune this to your exact needs.
      My Computer


  9. Posts : 9
    Windows 7
    Thread Starter
       #9

    Dear Alejandro85,
    thank you! The script is working like a charm but I have a problem: the file keep opened in the application and I cannot copy or overwrite it again.
    Does it is a way to kill Excel after the conversion automatically? That script should be executed every 60 seconds.
      My Computer


  10. Posts : 9
    Windows 7
    Thread Starter
       #10

    Dear Alejandro,
    I just added that to avoid the security warning when the script is launched...

    set oShell= CreateObject("Wscript.Shell")
    set oEnv = oShell.Environment("PROCESS")
    oEnv("SEE_MASK_NOZONECHECKS") = 1
    oShell.Run "script.vbs /norestart",0,True
    oEnv.Remove("SEE_MASK_NOZONECHECKS")
    but now we have to fix the issues of the message above as well the one for the security warning as the script is executed on a network drive.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:28.
Find Us