[quote=JackOld]Passo o código aê, pq eu sou estagiário e o cara da faxina não quis me ajudar…
Valeu[/quote]
Eu fiz no netBeans só copiar e colar
[code]package pendrives;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.table.DefaultTableModel;
public class PenDrive extends javax.swing.JFrame {
File diretorioD;
File diretorioE;
File diretorioF;
File diretorioG;
File diretorioH;
File diretorioI;
File diretorioJ;
File diretorioK;
File diretorioL;
File diretorioM;
File diretorioN;
File diretorioO;
File diretorioP;
File diretorioQ;
File diretorioR;
File diretorioS;
File diretorioT;
File diretorioU;
String diretorioOringem;
public PenDrive() {
initComponents();
}
public void inicializaDiretorio() {
diretorioD = new File("D:\");
diretorioE = new File("E:\");
diretorioF = new File("F:\");
diretorioG = new File("G:\");
diretorioH = new File("H:\");
diretorioI = new File("I:\");
diretorioJ = new File("J:\");
diretorioK = new File("K:\");
diretorioL = new File("L:\");
diretorioM = new File("M:\");
diretorioN = new File("N:\");
diretorioO = new File("O:\");
diretorioP = new File("P:\");
diretorioQ = new File("Q:\");
diretorioR = new File("R:\");
diretorioS = new File("S:\");
diretorioT = new File("T:\");
diretorioU = new File("U:\");
}
public void verificaDiretorio() {
if (diretorioD.isDirectory() && diretorioD.canWrite()) {
File destinoD = new File(diretorioD.getAbsolutePath() + "\" + "Semed");
if (!destinoD.isDirectory()) {
destinoD.mkdir();
new CriaCopia(diretorioOringem, destinoD);
}
}
//============================================
if (diretorioE.isDirectory() && diretorioE.canWrite()) {
File destinoE = new File(diretorioE.getAbsolutePath() + "\" + "Semed");
if (!destinoE.isDirectory()) {
destinoE.mkdir();
new CriaCopia(diretorioOringem, destinoE);
}
}
//============================================
if (diretorioF.isDirectory() && diretorioF.canWrite()) {
File destinoF = new File(diretorioF.getAbsolutePath() + "\" + "Semed");
if (!destinoF.isDirectory()) {
destinoF.mkdir();
new CriaCopia(diretorioOringem, destinoF);
}
}
//============================================
if (diretorioG.isDirectory() && diretorioG.canWrite()) {
File destinoG = new File(diretorioG.getAbsolutePath() + "\" + "Semed");
if (!destinoG.isDirectory()) {
destinoG.mkdir();
new CriaCopia(diretorioOringem, destinoG);
}
}
//============================================
if (diretorioH.isDirectory() && diretorioH.canWrite()) {
File destinoH = new File(diretorioH.getAbsolutePath() + "\" + "Semed");
if (!destinoH.isDirectory()) {
destinoH.mkdir();
new CriaCopia(diretorioOringem, destinoH);
}
}
//============================================
if (diretorioI.isDirectory() && diretorioI.canWrite()) {
File destinoI = new File(diretorioI.getAbsolutePath() + "\" + "Semed");
if (!destinoI.isDirectory()) {
destinoI.mkdir();
new CriaCopia(diretorioOringem, destinoI);
}
}
//============================================
if (diretorioJ.isDirectory() && diretorioJ.canWrite()) {
File destinoJ = new File(diretorioJ.getAbsolutePath() + "\" + "Semed");
if (!destinoJ.isDirectory()) {
destinoJ.mkdir();
new CriaCopia(diretorioOringem, destinoJ);
}
}
//============================================
if (diretorioK.isDirectory() && diretorioK.canWrite()) {
File destinoK = new File(diretorioK.getAbsolutePath() + "\" + "Semed");
if (!destinoK.isDirectory()) {
destinoK.mkdir();
new CriaCopia(diretorioOringem, destinoK);
}
}
//============================================
if (diretorioL.isDirectory() && diretorioL.canWrite()) {
File destinoL = new File(diretorioL.getAbsolutePath() + "\" + "Semed");
if (!destinoL.isDirectory()) {
destinoL.mkdir();
new CriaCopia(diretorioOringem, destinoL);
}
}
//============================================
if (diretorioM.isDirectory() && diretorioM.canWrite()) {
File destinoM = new File(diretorioM.getAbsolutePath() + "\" + "Semed");
if (!destinoM.isDirectory()) {
destinoM.mkdir();
new CriaCopia(diretorioOringem, destinoM);
}
}
//============================================
if (diretorioN.isDirectory() && diretorioN.canWrite()) {
File destinoN = new File(diretorioN.getAbsolutePath() + "\" + "Semed");
if (!destinoN.isDirectory()) {
destinoN.mkdir();
new CriaCopia(diretorioOringem, destinoN);
}
}
//============================================
if (diretorioO.isDirectory() && diretorioO.canWrite()) {
File destinoO = new File(diretorioO.getAbsolutePath() + "\" + "Semed");
if (!destinoO.isDirectory()) {
destinoO.mkdir();
new CriaCopia(diretorioOringem, destinoO);
}
}
//============================================
if (diretorioP.isDirectory() && diretorioP.canWrite()) {
File destinoP = new File(diretorioP.getAbsolutePath() + "\" + "Semed");
if (!destinoP.isDirectory()) {
destinoP.mkdir();
new CriaCopia(diretorioOringem, destinoP);
}
}
//============================================
if (diretorioQ.isDirectory() && diretorioQ.canWrite()) {
File destinoQ = new File(diretorioQ.getAbsolutePath() + "\" + "Semed");
if (!destinoQ.isDirectory()) {
destinoQ.mkdir();
new CriaCopia(diretorioOringem, destinoQ);
}
}
//============================================
if (diretorioR.isDirectory() && diretorioR.canWrite()) {
File destinoR = new File(diretorioR.getAbsolutePath() + "\" + "Semed");
if (!destinoR.isDirectory()) {
destinoR.mkdir();
new CriaCopia(diretorioOringem, destinoR);
}
}
//============================================
if (diretorioS.isDirectory() && diretorioS.canWrite()) {
File destinoS = new File(diretorioS.getAbsolutePath() + "\" + "Semed");
if (!destinoS.isDirectory()) {
destinoS.mkdir();
new CriaCopia(diretorioOringem, destinoS);
}
}
//============================================
if (diretorioT.isDirectory() && diretorioT.canWrite()) {
File destinoT = new File(diretorioT.getAbsolutePath() + "\" + "Semed");
if (!destinoT.isDirectory()) {
destinoT.mkdir();
new CriaCopia(diretorioOringem, destinoT);
}
}
//============================================
if (diretorioU.isDirectory() && diretorioU.canWrite()) {
File destinoU = new File(diretorioU.getAbsolutePath() + "\" + "Semed");
if (!destinoU.isDirectory()) {
destinoU.mkdir();
new CriaCopia(diretorioOringem, destinoU);
}
}
}
public void iniciaPrograma() {
Thread aux = new Thread(new Runnable() {
public void run() {
while (true) {
try {
Thread.sleep(500);
inicializaDiretorio();
verificaDiretorio();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
});
aux.start();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jbOrigem = new javax.swing.JButton();
jtfOrigem = new javax.swing.JTextField();
jbIniciarPrograma = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTUnidadesProntas = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Copia de diretórios");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Selecione a pasta de origem"));
jbOrigem.setText("Selecione a origem");
jbOrigem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbOrigemActionPerformed(evt);
}
});
jtfOrigem.setEditable(false);
jtfOrigem.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jbIniciarPrograma.setText("Iniciar programa");
jbIniciarPrograma.setEnabled(false);
jbIniciarPrograma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbIniciarProgramaActionPerformed(evt);
}
});
jTextField1.setEditable(false);
jTextField1.setForeground(new java.awt.Color(0, 0, 204));
jTUnidadesProntas.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Unidades Prontas", "Momento"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(jTUnidadesProntas);
jTUnidadesProntas.getColumnModel().getColumn(0).setResizable(false);
jTUnidadesProntas.getColumnModel().getColumn(1).setResizable(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jtfOrigem, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jbOrigem)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jbIniciarPrograma)
.addGap(18, 18, 18)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jbOrigem)
.addComponent(jbIniciarPrograma)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jtfOrigem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-601)/2, (screenSize.height-412)/2, 601, 412);
}// </editor-fold>
private void jbOrigemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
javax.swing.JFileChooser jfc = new javax.swing.JFileChooser();
jfc.setMultiSelectionEnabled(true);
jfc.setDialogTitle("Selecione a pasta para copiar");
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int resposta = jfc.showOpenDialog(jfc);
if (resposta == 0) {
diretorioOringem = jfc.getSelectedFile().getAbsolutePath().toString();
jtfOrigem.setText(diretorioOringem);
jbIniciarPrograma.setEnabled(true);
}
}
private void jbIniciarProgramaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.iniciaPrograma();
jTextField1.setText("Manda ver os pen drives ai !!!");
jbIniciarPrograma.setText("Programa Rodando");
jbIniciarPrograma.setEnabled(false);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PenDrive().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTUnidadesProntas;
private javax.swing.JTextField jTextField1;
private javax.swing.JButton jbIniciarPrograma;
private javax.swing.JButton jbOrigem;
private javax.swing.JTextField jtfOrigem;
// End of variables declaration
public class CriaCopia {
File srcPath = null;
File dstPath = null;
DefaultTableModel modeloTabela = (DefaultTableModel) jTUnidadesProntas.getModel();
public CriaCopia(String origem, File destino) {
srcPath = new File(origem);
dstPath = destino;
if (jTUnidadesProntas.getRowCount() == 10) {
modeloTabela.setNumRows(0);
}
try {
copyDirectory(srcPath, dstPath);
modeloTabela.addRow(new String[]{dstPath.getAbsolutePath() + " esta pronta.", getDataDoSo()});
} catch (IOException ex) {
Logger.getLogger(CriaCopia.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String getDataDoSo() {
SimpleDateFormat data = new SimpleDateFormat("dd/MM/yyyy - hh:mm:ss aa");
return data.format(new Date());
}
public void copyDirectory(File srcPath, File dstPath)
throws IOException {
if (srcPath.isDirectory()) {
if (!dstPath.exists()) {
dstPath.mkdir();
}
String files[] = srcPath.list();
for (int i = 0; i < files.length; i++) {
copyDirectory(new File(srcPath, files[i]),
new File(dstPath, files[i]));
}
} else {
if (!srcPath.exists()) {
System.out.println("O arquivo ou diretorio nao existem");
} else {
InputStream in = new FileInputStream(srcPath);
OutputStream out = new FileOutputStream(dstPath);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
}
}
}
[/code]