I basically have some code that will take a file, copy it's contents to another file, and delete the original. However, sometimes this makes the file name as a folder instead of a file. For example, it may make c:\file.txt as a FOLDER, not a text file. My code is below, which does sometimes work but like I said, it sometimes makes a folder instead. Does anyone have any ideas why?
File originalLogFile = new File(userDir + "/migration.log");
File renamedLogFile = new File(migrationLogFolder + "/" + runName + "/" + testFileName + ".txt");
trace("Trying to create file: " + renamedLogFile.getPath());
// If the folder doesn't exist, make it.
if(!renamedLogFile.exists()) {
renamedLogFile.mkdirs();
}
// Move and rename from migration.log to the above.
if(originalLogFile.exists()) {
if(renamedLogFile.exists()){
renamedLogFile.delete();
}
originalLogFile.renameTo(renamedLogFile);
}
Question
Annorax
Hi all,
I basically have some code that will take a file, copy it's contents to another file, and delete the original. However, sometimes this makes the file name as a folder instead of a file. For example, it may make c:\file.txt as a FOLDER, not a text file. My code is below, which does sometimes work but like I said, it sometimes makes a folder instead. Does anyone have any ideas why?
File originalLogFile = new File(userDir + "/migration.log"); File renamedLogFile = new File(migrationLogFolder + "/" + runName + "/" + testFileName + ".txt"); trace("Trying to create file: " + renamedLogFile.getPath()); // If the folder doesn't exist, make it. if(!renamedLogFile.exists()) { renamedLogFile.mkdirs(); } // Move and rename from migration.log to the above. if(originalLogFile.exists()) { if(renamedLogFile.exists()){ renamedLogFile.delete(); } originalLogFile.renameTo(renamedLogFile); }Any help is much appreciated.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts