SVicente's Blog

Follow me and you'll know what I like to do

Atualizando a versão do java no Linux Mint

Não é difícil! Basta seguir EXATAMENTE os passos contidos neste artigo de dicas do Ubuntu:

http://tipsonubuntu.com/2016/07/31/install-oracle-java-8-9-ubuntu-16-04-linux-mint-18/

Install Oracle Java 8 / 9 in Ubuntu 16.04, Linux Mint 18

Eu fiz passo a passo e deu certo:

> $ java -version

O comando responde:

java version “1.8.0_131”
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

 

 

July 14, 2017 Posted by | Linux, Programming | , , , | Leave a comment

MS-DOS Batch – copying files between directories

This weekend I took advantage of a free time and I did a task for a friend of mine. He had a specific situation that I decided to solve with a MS-DOS batch. To remember my old times as MS-DOS programmer.

The situation was: a series of mp3 files with coded names that were repeated. Because they were formed by a vinyl-to-cd recorder such that – FILE001.mp3, FILE002.mp3 and so on… And each album was saved in a folder named also coded as FOLD3001, FOLD3002, FOLD3003… My task was: move all mp3 files saved in each folder to ONLY ONE folder as repository and destination.

Graphically represented:

+— FOLD3001
|                           |— FILE001.mp3
|                           |— FILE002.mp3
|                           +– FILE007.mp3
+— FOLD3002
|                           |— FILE003.mp3
|                           |— FILE004.mp3
|                           |— FILE005.mp3
|                           +– FILE007.mp3

So what was my solution? Copy each file to destination folder before replacing its name to one that is preceded by folder name where it is originally saved.

This way:

+— _COPYFOLDER
         |— FOLD3001_FILE001.mp3
         |— FOLD3001_FILE002.mp3
         |— FOLD3001_FILE007.mp3
         |— FOLD3002_FILE003.mp3
         |— FOLD3002_FILE004.mp3
         |— FOLD3002_FILE005.mp3
         +– FOLD3002_FILE007.mp3

To get rid of possible filename collisions.

Thus, follow my two batch files to solve this special problem, but that could be adapted to many other similar situations envolved files and directories to move, copy and rename.

To execute this program:

  1. just copy these 2 files (“renome1.bat, renome2.bat”) to a same folder;
  2. customize according to your preferences: working variables (origin and destiny) in “renome1.bat”
  3. open a ms-dos command window;
  4. run “renome1.bat”;
  5. wait for final result.

Enjoy code!

@echo off

rem --------------------------------------------------------
rem file.....: renome1.bat
rem author...: twitter = @svicente99
rem date.....: Aug.11th 2012
rem objective: rename a set of files in multiple directories
rem --------------------------------------------------------

:---
:set working variables
set workDIR=D:\_PHILIPS
set v_copyDIR=D:\_COPY2

if not exist %v_copyDIR%\nul mkdir %v_copyDIR%

:---
for /d %%X in ( %workDIR%\*. ) do call renome2.bat %%X

:---
:End

del filename.txt
del dorename.bat

rem Show all copy files have being copied
dir %v_copyDIR%\. /w

set v_copyDIR=
set workDIR=

============================================================================

@echo off

: --------------------------------------------------------

: file.....: renome2.bat
: author...: twitter = @svicente99
: date.....: Aug.11th 2012
: objective: inner a directory rename files
:            called from 'renome1.bat'

: important references:

:   http://stackoverflow.com/questions/134001/how-can-i-load-the-contents-of-a-text-file-into-a-batch-file-variable
:   http://www.dostips.com/DtTipsStringManipulation.php#Snippets.StringConcatenation

: --------------------------------------------------------

if %1.==GoSub. goto GoSub

set v_folder=%1
echo Processing mp3 files in: %v_folder%
for %%f in ( %v_folder%\*.mp3 ) do call %0 GoSub dir /b/n %%f %%v_folder%%
goto End

:GoSub
set v_file_origin=%4
set v_folder=%5

goto SubRemove_MainFolder
:------------------------
:ReturnFor_SubRemove

rem Execute a dir /b/n to get only name of file
%2 %3 %4 > filename.txt

rem Set its name to a msdos variable using a special for
for /F "delims=" %%X in (filename.txt) do set v_nmFile=%%X

rem Create a batch command to copy file to "CopyDir"
echo copy /b/y %v_file_origin% %v_copyDIR%\%v_folder%_%%1 ^>nul > dorename.bat

rem Execute batch command to copy effectivelly
dorename.bat %v_nmFile%

goto End

:------------------------------
:SubRemove_MainFolder
set str=%v_folder%
echo.%str%
set str=%str:D:\_PHILIPS\=%
set v_folder=%str%
set str=
goto ReturnFor_SubRemove
:------------------------------

:End
set v_nmFile=
set v_folder=
set v_file_origin=

August 13, 2012 Posted by | Programming | , , | Leave a comment

Access – Open and read external table (VBA example)

Module: OpenDB

'================================================================================
'
' This VBA code demonstrates how to open a SQL Server database connection (or an
' MS Access database file) and to iterate through all records of its inner table
' Author.: svicente99@yahoo.com
' Date...: 2011, Apr.13
' Blog...: svicente99.wordpress.com
' Twitter: @svicente99
'
'================================================================================

Option Compare Database

Public Sub Main()
Dim oConn
Dim clDatabases As New Class_Databases
Dim clTables As New Class_Tables

oConn = clDatabases.fOpenSQLDatabase()
oConn = clDatabases.fOpenMDBAccess()
clTables.ReadTable (oConn)
Set oConn = Nothing
Set clDatabases = Nothing
End Sub

Class: Databases

Option Compare Database

Private Const SERVIDOR = "YOUR_SERVER\SQLEXPRESS"
Private Const MDB_FILE = "MDB_Path\bdReward-copy.mdb"
Private Const MDW_FILE = "System.mdw"
Private Const BANCO = "BD_TESTE"
Private Const USUARIO = "ubdteste"
Private Const SENHA = "tst"

Public Sub AbreBancoSQL()

Dim strConn As String

On Error Resume Next
Set cn = CreateObject("ADODB.Connection")

strConn = "Provider=SQLOLEDB.1;User ID=" & USUARIO & ";Password=" & SENHA & ";" & _
"Initial Catalog=" & BANCO & ";Data Source=" & SERVIDOR & ";" & _
"Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"

'MsgBox strConn
'abre efetivamente a conexao com o banco
cn.Open strConn

If Err.Number = 0 Then
MsgBox " Conexao efetuada com sucesso ! "
Else
MsgBox " Erro na abertura do banco " & BANCO & "." & vbCrLf & _
"Detalhes: " & Err.Description
On Error GoTo 0
Err.Clear
End If
End Sub

Public Function fOpenSQLDatabase()

Dim cn
Set cn = New ADODB.Connection

On Error Resume Next
cn.Provider = "SQLNCLI.1"
cn.Properties("Data Source").Value = SERVIDOR
cn.Properties("Initial Catalog").Value = BANCO
cn.Properties("User ID").Value = USUARIO
cn.Properties("Password").Value = SENHA
cn.Open 'effectively open database

If Err.Number = 0 Then
MsgBox " Success! Connection established. (SQL Server)"
fOpenSQLDatabase = cn
Else
MsgBox " Error ocurred while trying to open database " & BANCO & "." & vbCrLf & _
"Details: " & Err.Description
On Error GoTo 0
Err.Clear
End If

End Function

Public Function fOpenMDBAccess()

Dim cn
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = MDB_FILE
' .Properties("Jet OLEDB:System database") = MDW_FILE
' .Properties("User ID") = USUARIO
' .Properties("Password") = SENHA
.Properties("Persist Security Info") = False
.Properties("Mode") = adModeShareDenyNone
.Open
End With

If Err.Number = 0 Then
MsgBox " Success! Connection established. (Access) "
fOpenMDBAccess = cn
Else
MsgBox " Error ocurred while trying to open Access " & MDB_FILE & "." & vbCrLf & _
"Details: " & Err.Description
On Error GoTo 0
Err.Clear
End If

End Function

Class: Tables

Option Compare Database

Public Sub ReadTable(oConnection)

Dim nRecord As Integer
Dim str As String, SQL As String
Dim oCommand As New ADODB.Command
Dim oRecordSet As New ADODB.Recordset

SQL = "SELECT * FROM [1-entrada];"

With oCommand
.ActiveConnection = oConnection
.CommandText = SQL
.CommandType = adCmdText
End With

'Defines our RecordSet object.

' .CursorType sets a static cursor, the only choice for a client side cursor
' .CursorLocation sets a client side cursor, the only choice for an Access database
' .LockType sets an optimistic lock type
' .Open executes the cmdCommand object against the data source and stores the
' returned records in our RecordSet object.

With oRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open oCommand
End With

nRecord = 1
With oRecordSet
While Not .EOF
str = nRecord & "º record ------------" & vbCrLf
str = str & "ID_FUN: " & .Fields(0) & vbCrLf
str = str & "CODAUS: " & .Fields(1) & vbCrLf
str = str & "GRPAUS: " & .Fields(2) & vbCrLf
str = str & "DTINICIAL: " & .Fields(3) & vbCrLf
str = str & "DTFINAL: " & .Fields(4) & vbCrLf & vbCrLf
str = str & "[ stop w/ Ctrl-Break ]"
MsgBox str
.MoveNext
nRecord = nRecord + 1
Wend
.Close
End With

Set oRecordSet = Nothing
Set oCommand = Nothing

End Sub



To download an Access database where this example was programmed, just click:
Bd Access 2003 – How to open and read a external table

April 14, 2011 Posted by | Programming | , , , | Leave a comment

Access – how to open a SQL Server database (VBA example)

'=========================================================================
'
' This VBA code demonstrates how to open a SQL Server database connection
' Author.: svicente99@yahoo.com
' Date...: 2011, Apr.12
' Blog...: svicente99.wordpress.com
' Twitter: @svicente99
'
'=========================================================================

Option Compare Database

Private Const SERVIDOR = "YOURSERVER\SQLEXPRESS"
Private Const BANCO = "BD_TESTE"
Private Const USUARIO = "ubdteste"
Private Const SENHA = "tst"

Public Sub Main()
Call AbreBancoSQL
Call OpenSQLDatabase
End Sub

Private Sub AbreBancoSQL()

Dim strConn As String

On Error Resume Next
Set cn = CreateObject("ADODB.Connection")

strConn = "Provider=SQLOLEDB.1;User ID=" & USUARIO & ";Password=" & SENHA & ";" & _
"Initial Catalog=" & BANCO & ";Data Source=" & SERVIDOR & ";" & _
"Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"

'MsgBox strConn
'abre efetivamente a conexao com o banco
cn.Open strConn

If Err.Number = 0 Then
MsgBox " Conexao efetuada com sucesso ! "
Else
MsgBox " Erro na abertura do banco " & BANCO & "." & vbCrLf & _
"Detalhes: " & Err.Description
On Error GoTo 0
Err.Clear
End If
End Sub

Private Sub OpenSQLDatabase()

Set cn = New ADODB.Connection

On Error Resume Next
cn.Provider = "SQLNCLI.1"
cn.Properties("Data Source").Value = SERVIDOR
cn.Properties("Initial Catalog").Value = BANCO
cn.Properties("User ID").Value = USUARIO
cn.Properties("Password").Value = SENHA
cn.Open 'effectively open database

If Err.Number = 0 Then
MsgBox " Success! Connection established. "
Else
MsgBox " Error ocurred while trying to open database " & BANCO & "." & vbCrLf & _
"Details: " & Err.Description
On Error GoTo 0
Err.Clear
End If

End Sub


To download an Access database where this example was programmed, just click:
Bd Access 2003 – Modulo 1 – How to open a SQL Server database

April 13, 2011 Posted by | Programming | , , , | Leave a comment