Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5552 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hey Nick - here are two modules I just wrote up. I've added them to the ScriptMaster.fp7 file, so they'll be in the next release.

=== CreateFolder ===

This takes an operating system path as a parameter (for example, /Users/Shared/newFolder or C:Documents and SettingsMyAccountnewFolder) and creates that folder. It returns a 1 if the folder was created, 0 if it already exists, and an error if the folder does not exist and could not be created. It will create nested subdirectories, so if /Users/Shared existed and you use /Users/Shared/a/b/c as the path, it will create folders a, b, and c.

This takes one parameter, 'pathToCreate':


File dir = new File(pathToCreate);

if( dir.exists() ) return false;

if( dir.mkdirs() ) {

	return true;

} else {

	File realParent = dir;

	while( realParent != null && ! realParent.exists() ) {

		realParent = realParent.getParentFile();

	}

	if( realParent != null && !realParent.canWrite() ) {

		throw new FileNotFoundException("Directory " + dir.getAbsolutePath() + " could not be created because the parent directory " + realParent.getAbsolutePath() + " is not writeable" );

	} else {

		throw new FileNotFoundException("Directory + " + dir.getAbsolutePath() + " could not be created because of an unknown error." );

	}

}





===DeleteFileOrFolder===

This takes an operating system path as a parameter (for example, /Users/Shared/newFolder or C:Documents and SettingsMyAccountnewFolder) and deletes that folder or file. It returns a 1 if the folder or file was deleted, 0 if it does not exist, and an error if the folder or any of its contents could not be deleted. It will recursively delete subdirectories, so be careful!



this takes one parameter, 'pathToDelete':





File toDelete = new File(pathToDelete);

if( ! toDelete.exists() ) {

	return false;

} else {

	deleteRecursive( toDelete );

}



void deleteRecursive( File fileToDelete ) throws IOException {

	if( fileToDelete.isDirectory() ) {

		File[] children = fileToDelete.listFiles();

		for( int n=0; n

  • 1 month later...
  • 4 weeks later...
Posted

I'm using DeleteFileOrFolder() on both Mac & PC. It seems to work for me but with unexpected returned results.

I found that when the file is successfully deleted, the return result is EMPTY instead of 1. I do get a 0 if the file does not exist.

ALSO, DeleteFileOrFolder() deletes the file even if it is open by another application. (MSWord gets really confused when that happens.) I was originally checking for an error code so I could warn the user.

...Mike

This topic is 5552 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.