Last active
August 27, 2019 17:52
-
-
Save gustavorps/453dfb6af422e0ea5a32f26107d8c1c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(read.dbc) | |
| library(R.utils) | |
| library(stringr) | |
| library(base) | |
| library(tools) | |
| file_format_choices = c('csv', 'tsv') | |
| file_format = file_format_choices[menu(file_format_choices, 'Formato de conversão')] | |
| arq_local = choose.dir(caption = "Diretório com arquivos DBC") | |
| arq_destino = choose.dir(caption = "Diretório de destino") | |
| arq_pattern = "(ABO|ACF|AD|AM|AN|AQ|AR|ATD|BI|PA|PS|DO|DN)(ES).*\\.(dbc|DBC)$" | |
| setwd(arq_local) | |
| files = list.files(path='.', pattern=arq_pattern) | |
| lista = NULL | |
| for (i in 1:length(files)) { | |
| print(paste(i, " = ", files[i])) | |
| lista = read.dbc(files[i]) | |
| gz = gzfile(gettextf("%s\\%s.%s.gz", | |
| arq_destino, | |
| file_path_sans_ext(files[i]), | |
| file_format)) | |
| # TODO: refactor | |
| if (file_format == 'csv') { | |
| write.csv(x = lista, | |
| file = gz, | |
| quote=FALSE, | |
| sep=',', | |
| row.names=FALSE) | |
| } else if (file_format == 'tsv') { | |
| write.table(x = lista, | |
| file = gz, | |
| quote=FALSE, | |
| sep='\t', | |
| row.names=FALSE) | |
| } else { | |
| stop('Formato não suportado ') | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outra alternativa para conversão de arquivos
.dbcpor pastas