cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
lala
Level IX

How to delete all files in a folder?

A folder contains no folders but multiple files.
How can I delete these files using JSL?


Because this folder is occupied by other levels, cannot be achieved by deleting the folder.

rd1=Delete Directory(dir);rc1=Create Directory(dir);

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to delete all files in a folder?

If you want to just delete the files, here is a modification on @jthi code to do that

Names Default To Here( 1 );

dir_path = "$TEMP\test\";

If( !Directory Exists( dir_path ),
	Create Directory( dir_path );
	new_file = Save Text File(
		dir_path || "DeleteMe.txt",
		"The quick brown fox"
	);
	new_file = Save Text File(
		dir_path || "DeleteMe2.txt",
		"The quick brown fox"
	);
);

Wait( 1 );

// Get the files in the folder
the_Files = Files In Directory( dir_path );

For Each( {file}, the_files, rc = Delete File( dir_path || file ) );

Show( Files In Directory( dir_path ) );
Jim

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How to delete all files in a folder?

For me the directory gets deleted even if it has files. Maybe some of your files are still being used?

Names Default To Here(1);

dir_path = "$TEMP\test\";

If(!Directory Exists(dir_path),
	Create Directory(dir_path);
	new_file = Save Text File(dir_path || "DeleteMe.txt", "The quick brown fox");
	new_file = Save Text File(dir_path || "DeleteMe2.txt", "The quick brown fox");
);

wait(1);
Show(Directory Exists(dir_path));
Show(Files In Directory(dir_path));
Show(File Exists(new_file));

Delete Directory(dir_path);

wait(1);

Show(File Exists(new_file));
Show(Directory Exists(dir_path));

-Jarmo
txnelson
Super User

Re: How to delete all files in a folder?

If you want to just delete the files, here is a modification on @jthi code to do that

Names Default To Here( 1 );

dir_path = "$TEMP\test\";

If( !Directory Exists( dir_path ),
	Create Directory( dir_path );
	new_file = Save Text File(
		dir_path || "DeleteMe.txt",
		"The quick brown fox"
	);
	new_file = Save Text File(
		dir_path || "DeleteMe2.txt",
		"The quick brown fox"
	);
);

Wait( 1 );

// Get the files in the folder
the_Files = Files In Directory( dir_path );

For Each( {file}, the_files, rc = Delete File( dir_path || file ) );

Show( Files In Directory( dir_path ) );
Jim
lala
Level IX

Re: How to delete all files in a folder?

Thanks!

 

I can't use Windows 7 anymore.

Be sure to use JMP 16.

Powerful For Each()

For Each( {file}, the_files, rc = Delete File( dir_path || file ) );

Recommended Articles