import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import javax.swing.*;
public class OrdnerDateienUmb extends JFrame
implements ActionListener
{ JButton ordner;
JButton ausführen;
JTextField text;
JFileChooser in;
String filein;
public OrdnerDateienUmb()
{ Container c = getContentPane();
ordner = new JButton("Ordner");
ausführen = new JButton("Ausführen");
text = new JTextField();
JTextArea info = new JTextArea("Ordner: Wählen sie den Ordner aus, in dem die Dateien umbenannt werden sollen.\n Im Textfeld geben sie den Text ein, der in der Klammer stehen soll.");
info.setEditable(false);
JPanel buttons = new JPanel();
JPanel main = new JPanel();
c.setLayout(new BorderLayout());
buttons.setLayout(new GridLayout(1,2));
main.setLayout(new GridLayout(2,1));
c.add(buttons, BorderLayout.SOUTH);
c.add(main, BorderLayout.CENTER);
buttons.add(ordner);
buttons.add(ausführen);
main.add(text);
main.add(info);
ordner.setBorder(BorderFactory.createEtchedBorder());
ausführen.setBorder(BorderFactory.createEtchedBorder());
info.setBorder(BorderFactory.createEtchedBorder());
text.setBorder(BorderFactory.createEtchedBorder());
ordner.addActionListener(this);
ausführen.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{ try
{ if(ordner == event.getSource())
{ JFrame f = new JFrame();
in = new JFileChooser();
in.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = in.showOpenDialog(in);
if (returnVal == JFileChooser.APPROVE_OPTION)
{ File eins = in.getSelectedFile();
filein = eins.getPath();
}
in.setVisible(true);
}
if(ausführen == event.getSource())
{ umbenennen(filein);
}
}
catch(Exception e)
{
}
}
public void umbenennen(String ordner)
{ try
{ File userdir = new File (ordner);
String entries[]=userdir.list();
for ( int i = 0; i < entries.length; i++ )
{ int k;
String[] title = new String[entries.length];
String[] neu = new String[entries.length];
k = entries[i].indexOf(".");
if (k<0)
title[i] = entries[i];
else
title[i] = entries[i].substring(k);
String eins = text.getText();
neu[i] = ordner + "\\" + title[i] + "-" + eins + "-" + ".mp3";
File ein = new File(entries[i]);
File aus = new File(neu[i]);
ein.renameTo(aus);
}
}
catch(Exception e)
{
}
}
public static void main(String[] args)
{ JFrame start = new OrdnerDateienUmb();
start.setSize(610,300);
start.setLocationRelativeTo(null);
start.setVisible(true);
}
}