private void deleteFiles(Connection dbConnection) {
			
			logger.info("Polling for files pending deletion...");
			try {
				PreparedStatement s = dbConnection.prepareStatement("SELECT * FROM files WHERE ready_for_processing=1 AND ((heartbeat IS NULL OR heartbeat<?) AND (ready_for_delete=1 OR (in_use=0 AND session_id IS NULL)))"+getFileTypeIdsWhereString("file_type_id"));
				int i = 1;
				s.setTimestamp(i++, heartbeatManager.getProcessingFilesTimestamp());
				for (FileType a : FileType.values()) {
					s.setInt(i++, a.getObj().getId());
				}
				ResultSet r = s.executeQuery();
				
				while(r.next()) {
					File file = DbHelper.buildFileFromResult(r);
					logger.info("Attempting to remove file with id "+file.getId()+" and any child files it has.");
					if (!removeChildFilesAndRecords(dbConnection, file, true)) {
						logger.warn("Some files could not be removed for some reason and the file record for this (id "+file.getId()+") still exists.");
					}
				}
				s.close();
			} catch (SQLException e) {
				logger.error("SQLException when trying to query databases for files that need deleting.");
				e.printStackTrace();
			}
			logger.info("Finished polling for files pending deletion.");
		}