cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

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