Need advice > converting category assignments to custom post meta values

Basic idea would be to loop through posts and their categories, assigning meta on matches.

Something like this (be sure to check on test copy of data, etc, etc):

$posts = get_posts( array(
    'numberposts' => -1
) );

foreach( $posts as $post ) {

    $categories = get_the_category( $post->ID );

    foreach( $categories as $category ) {

        if( 'Hidden' ==  $category->name )
            add_post_meta( $post->ID, '_hidden', 'yes', true );
    }

}

Forgot to add deleting when done:

$category = get_category_by_slug( 'hidden' );
wp_delete_category( $category->term_id );