Index: src/wp-admin/includes/class-wp-comments-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-comments-list-table.php	(revision 40294)
+++ src/wp-admin/includes/class-wp-comments-list-table.php	(working copy)
@@ -354,7 +354,7 @@
 			submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 		}
 
-		if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) ) {
+		if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $this->has_items() ) {
 			wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
 			$title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
 			submit_button( $title, 'apply', 'delete_all', false );
Index: src/wp-admin/includes/class-wp-media-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-media-list-table.php	(revision 40294)
+++ src/wp-admin/includes/class-wp-media-list-table.php	(working copy)
@@ -177,7 +177,7 @@
 			submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 		}
 
-		if ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) {
+		if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
 			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
 		} ?>
 		</div>
Index: src/wp-admin/includes/class-wp-posts-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-posts-list-table.php	(revision 40294)
+++ src/wp-admin/includes/class-wp-posts-list-table.php	(working copy)
@@ -489,7 +489,7 @@
 			}
 		}
 
-		if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
+		if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
 			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
 		}
 ?>
Index: src/wp-admin/js/edit-comments.js
===================================================================
--- src/wp-admin/js/edit-comments.js	(revision 40294)
+++ src/wp-admin/js/edit-comments.js	(working copy)
@@ -461,6 +461,14 @@
 			updateCountText( 'span.trash-count', trashDiff );
 		}
 
+		if ( ( 'trash' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.trash-count' ) ) ) {
+			$( '#delete_all' ).hide();
+ 		}
+		
+		if ( ( 'spam' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.spam-count' ) ) ) {
+			$( '#delete_all' ).hide();
+ 		}
+
 		if ( ! isDashboard ) {
 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
 			if ( $(settings.target).parent().is('span.undo') )
Index: tests/phpunit/tests/admin/includesListTable.php
===================================================================
--- tests/phpunit/tests/admin/includesListTable.php	(revision 40294)
+++ tests/phpunit/tests/admin/includesListTable.php	(working copy)
@@ -235,4 +235,18 @@
 
 		$this->assertNotContains( 'id="cat"', $output );
 	}
+
+	/**
+	 * @ticket 38341
+	 */
+	function test_empty_trash_button_should_not_be_shown_if_there_are_no_posts() {
+		// Set post type to a non-existent one.
+		$this->table->screen->post_type = 'foo';
+
+		ob_start();
+		$this->table->extra_tablenav( 'top' );
+		$output = ob_get_clean();
+
+		$this->assertNotContains( 'id="delete_all"', $output );
+	}
 }
