Use JavaScript to create a folder structure from a loop in the SharePoint library

Prerequisite is the creation of a folder structure from an array in a SharePoint library with JavaScript. Below is the desired structure:

var ary = (A,B,C)

A -> Fldr1 -> Fldr2 -> File
B -> Fldr1 -> Fldr2 -> File
C -> Fldr1 -> Fldr2 -> File

Currently, build folders A, B, and C are created in the library, but within the structure, for C only.

The result is:

A 
B 
C -> Fldr1 -> Fldr2 -> File

The following code works perfectly if there is only one element in the array, but fails if there are multiple elements. Here I check if there are any folders, then check if level 2 exists, first create etc., to find the remaining structure.

 async function processArray(selectedCountries) {
await selectedCountries.map(async (item) => {       
  let promiseCntry = await checkCntryFolder(item);       
    if(flag){ //if cntry exists                      
         let promiseChckfolder = await checkFolder(tdmrkNm);
                if(flagFldr)//if folder exists
                {                           
                    let promiseChkSubFolder =  await checkSubFolder(appStatus);
                        if(flagSub)//if sub -folder exists
                        {                                    
                             let createFile =  await CreateFileInSideFolder();
                        }
                        else
                        {                                
                            let promiseCreateSub =  await createSubFolder(appStatus);                                        
                            let createFile =  await CreateFileInSideFolder();
                        }                   
                }
                else//if folder doesn't exist
                {                            
                         let createFldr =  await createFolder(tdmrkNm);
                         let promiseChkSubFolder =  await checkSubFolder(appStatus);
                            if(flagSub)
                            {                                               
                                let createFile =  await CreateFileInSideFolder();   
                            }
                            else
                            {                                    
                                let promiseCreateSub =  await createSubFolder(appStatus);
                                let createFile =  await CreateFileInSideFolder();   
                            } 
                }
        }
        else//if cntry doesn't exist
        {                    
                 let createCntry = await createCntryFolder(item);             
                 let promiseChckfolder =  await checkFolder(tdmrkNm);                                               
                    if(flagFldr)//if folder exists
                    {                                 
                         let promiseChkSubFolder =  await checkSubFolder(appStatus);
                            if(flagSub) //if sub-folder exists
                            {                                            
                                let createFile =  await CreateFileInSideFolder();       
                            }
                            else //if sub-folder doesn't exist
                            {                                                                           
                                 let promiseCreateSub =  await createSubFolder(appStatus);                                            
                                 let createFile =  await CreateFileInSideFolder();
                            }                                           
                    }
                    else //if folder doesn't exist
                    {                           

                         let createFldr =  await createFolder(tdmrkNm);
                         let promiseChkSubFolder =  await checkSubFolder(appStatus);
                                if(flagSub)//if sub-folder exists
                                { 
                                    let createFile = await CreateFileInSideFolder();
                                }
                                else//if sub-folder doesn't exist
                                { 
                                    let promiseCreateSub =  await createSubFolder(appStatus);
                                    let createFile =  await CreateFileInSideFolder();   
                                } 

                    }   
        }

    });
  }
}

Endless loop in C

I'm trying to make a linear linked-assignment list in C and getting into an infinite loop.

void busca(Lista L, int x, No* ant, No* pont){
No ptr;

*pont = NULL;
*ant = L->ptLista;
ptr = (*ant)->prox;

while (ptr != NULL){
    if (ptr->valor < x){
        *ant = ptr;
        ptr = ptr->prox;
    }else{
        if(ptr->valor == x){
            *pont = ptr;
            printf("Numero encontradon");
        }

        ptr == NULL;
        printf("Saindon");
    }   
}}

(No = typedef struct no * No)
(List = typedef struct list * List)
This function searches for the integer X. However, if the integer X is found in the list, ptr is not set to NULL and enters an infinite loop. Can someone help me?

Error 500 in loop to create posts and thumbnails

I use this loop to read a folder and create a custom post with the basename information.

However, with about 20 images, the answer is a 500 error and the process is aborted. I'm looking for a tip to make it faster. I have about 1000 pictures. By the way, I think the problem lies in it

$attach_data  = wp_generate_attachment_metadata( $attach_id, $file);
wp_update_attachment_metadata( $attach_id, $attach_data );

but I am not sure.

The loop is:

    public function run() {

    //  Caminho do servidor
    $where_read = ABSPATH . 'arquivos-ambientes';
    // $al_location = ABSPATH . 'upload/ambientes';

    // Pega apenas arquivos, ignorando o que não tiver extensão ( pastas )
    $files_array = glob( $where_read . "/*.{*}", GLOB_BRACE );

    $sufixo_amb = '-amb';
    $sufix_foto = 'foto-';

    $args = (
        'numberposts'   => -1,
        'post_type'     => 'produtos_teste',
        'post_status'   => 'any'
    );

    $all_products = get_posts( $args );

    foreach( $all_products as $ap ) {

        $slugs()    = $ap->post_name;
        $post_ids() = $ap->ID;

    }

    $ac = 'stringstringstringstringstringstring';
    foreach( $files_array as $file ) {

        $file_base_name = basename( $file, '.jpg' );
        $what_is_this() = $file_base_name;

        $slugs_found = ();
        $products_ids = ();

        foreach( $slugs as $key => $s ) {

            $sm = strpos( $file_base_name, $s );

            if( $sm !== false ) {

                $file_names() = $file_base_name;
                $slugs_found() = $s;
                $products_ids() = $post_ids($key); 

            }

        }

        $slugs_each() = $slugs_found;
        $products_ids_each() = $products_ids;

        if( substr( $file_base_name, 0, -2 ) == $ac ) {
            $galery_check = true;
        } else {
            $galery_check = false;
        }

        $ac = substr($file_base_name, 0, -2);

        $fotografo = ' ';
        if( strpos( $file_base_name, $sufix_foto ) !== false ) {

            if( strpos( $file_base_name, $sufix_foto ) !== false ) {

                $nome = $this->get_between_word( $file_base_name, $sufix_foto, $sufixo_amb );
                $fotografo = str_replace( '-', ' ', $nome );

            }

        }

        if( isset( $galery_check ) ) {

            $ambiente_name    = 'Ambiente Eliane: ' . str_replace('eliane-', '', $file_base_name);
            $ambientes() = (

                'post_title'    => $ambiente_name,
                'base_name'     => $file_base_name,
                'ambiente'      => get_current_user_id(),
                'produtos'      => $products_ids,    //array id dos produtos
                'fotografia'    => $fotografo,
                'check'         => $galery_check,
                'file'          => $file

            );

        }     

    }

    $upload_dir = wp_upload_dir();
    $last_one = count($ambientes);
    $counter = 0;
    // $category_id = 458;
    foreach( $ambientes as $amb ) {

        if( $amb('check') === false ) {

            if( isset( $galeria ) ) {
                update_post_meta( $ind_post_id, 'galeria', $galeria ); 
                $aqui = (
                    'post_id' => $ind_post_id,
                    'galeria' => $galeria
                );
                $update_galerias() = $aqui;
            }

            $galeria = ();

            $image_url  = $amb('file');
            $or_name    = $amb('file');
            $image_data = file_get_contents( $image_url );
            $filename   = basename( $image_url );

            if ( wp_mkdir_p( $upload_dir('path') ) ) {
                $file = $upload_dir('path') . '/ambientes/' . $filename;
            } else {
                $file = $upload_dir('basedir') . '/ambientes/' . $filename;
            }

            file_put_contents( $file, $image_data );
            $wp_filetype = wp_check_filetype( $filename, null );

            $attachment = (

                'post_mime_type' => $wp_filetype('type'),
                'post_title'     => sanitize_file_name( $filename ),
                'post_content'   => '',
                'post_status'    => 'inherit'

            );

            $attach_id  = wp_insert_attachment( $attachment, $file);
            $att_ids() = $attach_id . ' --- thumb ';
            require_once( ABSPATH . 'wp-admin/includes/image.php' );

            // Gera os metadatas necessários para que os attachments funcionem normalmente.
            $attach_data  = wp_generate_attachment_metadata( $attach_id, $file);
            wp_update_attachment_metadata( $attach_id, $attach_data );

            $status = 'publish';
            $in_args = (

                'post_title'    => $amb('post_title'),
                'post_content'  => '',
                'post_status'   => $status,
                'post_type'     => 'ambientes'

            );

            $ind_post_id = wp_insert_post( $in_args );
            wp_set_object_terms( $ind_post_id, array(461), 'categoria-ambiente' );
            $ids_dos_ambientes() = $ind_post_id;
            update_post_meta( $ind_post_id, 'ambiente', get_current_user_id() );
            update_post_meta( $ind_post_id, 'fotografia', $amb('fotografia') );
            update_post_meta( $ind_post_id, 'produtos', $amb('produtos') );
            set_post_thumbnail( $ind_post_id, $attach_id );
            unlink($or_name);

        } else {

            $image_url  = $amb('file');
            $or_name    = $amb('file');
            $image_data = file_get_contents( $image_url );
            $filename   = basename( $image_url );

            if ( wp_mkdir_p( $upload_dir('path') ) ) {
                $file = $upload_dir('path') . '/ambientes/' . $filename;
            } else {
                $file = $upload_dir('basedir') . '/ambientes/' . $filename;
            }

            file_put_contents( $file, $image_data );
            $wp_filetype = wp_check_filetype( $filename, null );
            $attachment = (

                'post_mime_type' => $wp_filetype('type'),
                'post_title'     => sanitize_file_name( $filename ),
                'post_content'   => '',
                'post_status'    => 'inherit'

            );

            $attach_id  = wp_insert_attachment( $attachment, $file);
            $att_ids() = $attach_id . ' --- galeria ';
            require_once( ABSPATH . 'wp-admin/includes/image.php' );

            // Gera os metadatas necessários para que os attachments funcionem normalmente.
            $attach_data  = wp_generate_attachment_metadata( $attach_id, $file);
            wp_update_attachment_metadata( $attach_id, $attach_data );
            $galeria() = $attach_id;
            unlink($or_name);

        }

        $counter++;
        if( ( $counter ) == $last_one && $amb('check') === true ) {
            update_post_meta( $ind_post_id, 'galeria', $galeria );
            $aqui = (
                'post_id' => $ind_post_id,
                'galeria' => $galeria
            );
            $update_galerias() = $aqui;
        }
    }

    $response = (
        'infos-nas-galerias' => $update_galerias,
        'att_ids'           => $att_ids,
        'ids_dos_ambientes' => $ids_dos_ambientes
    );

    return $response;
}

You will see some & # 39; Galeria & # 39; things, it's a meta of ACF, and those parts of the code work (the image galleries are fine).

get_between_word It's just a function to read some strings in basename. Well, my problem is with the pictures. When I run without wp_generate and wp_update, everything works, but no thumbnails (the images with the standard sizes of WordPress) are created.

Which condition or loop to use

How do I do this so that if my condition is not met, I ask again until I have entered correctly?

Example: The user had to enter numbers between 1 and 12, he does not give it to me

void pedir_num(int num){

int num1;
printf("escriba un numero del 1-12");
scanf("%i", num1);
int rango;
for ( rango=0; rango<=12; rango++)  {

    do {        
        printf("Introdusca correctamente");
} while (num1 != rango);

}

int main(){

int num;

pedir_num(&num);

return 0;

}

jquery – mediaelements.js + playlist loop does not work. How do I pause playing the last item in the list?

I have the latest version of mediaelements.js with the playlist plugin (https://github.com/r4fx/mediaelement-playlist). It has not been updated for years, so I need to find creative ways to fix a problem.

The repeat function plays either the first track or the entire playlist and repeats them. I'm trying to find a way to play the playlist once and then pause. I think the best way to do that is to add a class called last and then stop the player at the end with the end function, but I can not seem to get it up and running.

Code:

if ($.fn.mediaelementplayer) {
        $('audio.mediaElementPlaylist').mediaelementplayer({
            audioWidth: '100%',
            alwaysShowControls: true,
            playlist: true,
            success: function (mediaElement, domObject) {
              mediaElement.addEventListener('ended', function (e) {
                  mejsPlayNext(e.target);
              }, false);
          },
          success: function(mediaElement, node) {
            if($(this).hasClass('last')) {
              mediaElement.addEventListener('ended', function(e){
                mediaElement.pause();
              });
            };
          },
          error: function (media, node) {
                $(media).parents('.mediaElementPlaylist').addClass('playlist_cannotplay');
          },
          features: ('playlistfeature', 'prevtrack', 'playpause', 'nexttrack', 'playlist', 'current', 'progress', 'duration', 'volume'),
        });
        $(".mejs__playlist ul li:last-child").addClass("last");
};

Code that stops the player when finished:

success: function(mediaElement, node) {
            if($(this).hasClass('last')) {
              mediaElement.addEventListener('ended', function(e){
                mediaElement.pause();
              });
            };
          },

https://codepen.io/openbayou/pen/LYPezGB

compile – How can I jump to the end of a loop if a compiled function returns an error?

This is a kind of follow-up to my question. How do you just bypass a step in an iterative process that generates an error?
what I have not been able to do (stubbornly) to incorporate into my specific code.

The code at the end executes a three-level loop with the index i95 from 16,630,332 to 16,630,334. At 16,630,333, a compiled malfunction is generated. I want to jump immediately to (eax) at the end of the loop, skip the intermediate calculations and raise the index to 16,630,334.
The function in question is

t4 = Compile({a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, l1, l2, l3, l4}, Haar s3,CompilationTarget -> "C",RuntimeAttributes -> {Listable}, Parallelization -> True);

The full code (running fast) I'm trying to implement (the function is about 2/3 of the way down) is

S = {{{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0,
0}}, {{0, -I, 0, 0}, {I, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0,
0}}, {{1, 0, 0, 0}, {0, -1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0,
0}}, {{0, 0, 1, 0}, {0, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0,
0}}, {{0, 0, -I, 0}, {0, 0, 0, 0}, {I, 0, 0, 0}, {0, 0, 0,
0}}, {{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0,
0}}, {{0, 0, 0, 0}, {0, 0, -I, 0}, {0, I, 0, 0}, {0, 0, 0,
0}}, {{1 / Sqrt (3), 0, 0, 0}, {0, 1 / Sqrt (3), 0, 0}, {0,
0, -2 / Sqrt (3), 0}, {0, 0, 0, 0}}, {{0, 0, 0, 1}, {0, 0, 0, 0}, {0,
0, 0, 0}, {1, 0, 0, 0}, {{0, 0, 0, -I}, {0, 0, 0, 0}, {0, 0, 0,
0}, {I, 0, 0, 0}, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0
1, 0, 0}}, {{0, 0, 0, 0}, {0, 0, 0, -I}, {0, 0, 0, 0}, {0, I, 0,
0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1,
0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, -I}, {0, 0, I,
0}}, {{1 / Sqrt (6), 0, 0, 0}, {0, 1 / Sqrt (6), 0, 0}, {0, 0,
1 / Sqrt (6), 0}, {0, 0, 0, -Sqrt (3/2)}}};
f1 (x_, y_): = MatrixExp (IS ((x)) y); U =
f1 (3, a1) .f1 (2, a2) .f1 (3, a3) .f1 (5, a4) .f1 (3, a5) .f1 (10, a6) .f1 (3,
a7) .f1 (2, a8) .f1 (3, a9) .f1 (5, a10) .f1 (3, a11) .f1 (2, a12); Hair =
Cos (a4) ^ 3 Cos (a6) Cos (a10) Sin (2 a2) Sin (a4) Sin (a6) ^ 5 Sin (
2 a8) Sin (a10) ^ 3 Sin (
2 a12) ((l1 – l2) ^ 2 (l1 – l3) ^ 2 (l2 – l3) ^ 2 (l1 – l4) ^ 2 (l2 –
l4) ^ 2 (l3 – l4) ^ 2) / Sqrt (l1, l2, l3, l4); X =
Compile ({a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12}, U,
RuntimeAttributes -> {Listable},
Parallelization -> true); s3 = {Sqrt (l1, l2, l3, l4),
64 / ((l1 + l2) (l1 + l3) (l2 + l3) (l1 + l4) (l2 + l4) (l3 +
l4)), ((l1 + l2) (l1 + l3) (l2 + l3) (l1 + l4) (l2 + l4) (l3 +
l4)) / (64 l1 ^ 3 l2 ^ 3 l3 ^ 3 l4 ^ 3), ((Log (l1) – Log (l2)) (Log (l1) –
Protocol (l3)) (Protocol (l2) – Protocol (l3)) (Protocol (l1) – Protocol (l4)) (Protocol (l2) –
Log (l4)) (Log (l3) – Log (l4)) / ((l1 – l2) (l1 – l3) (l2 –
l3) (l1 – l4) (l2 – l4) (l3 – l4)), 1 / (
11 ^ (3/2) 12 ^ (3/2) 13 ^ (3/2) 14 ^ (3/2)),
4096 / ((Sqrt (l1) + Sqrt (l2)) ^ 2 (Sqrt (l1) + Sqrt (l3)) ^ 2 (Sqrt (l2) +
Sqrt (13)) ^ 2 (Sqrt (l1) + Sqrt (l4)) ^ 2 (Sqrt (l2) + Sqrt (
14)) ^ 2 (sqrt (13) + sqrt (
l4)) ^ 2), ((l1 + l2) (l1 + l3) (l2 + l3) (l1 + l4) (l2 + l4) (l3 +
l4) (Log (l1) – Log (l2)) (Log (l1) – Log (l3)) (Log (l2) –
Protocol (l3)) (Protocol (l1) – Protocol (l4)) (Protocol (l2) – Protocol (l4)) (Protocol (l3) –
Log (l4)) / (64 l1 ^ (3/2) (l1 – l2) l2 ^ (
3/2) (l1 – l3) (l2 – l3) l3 ^ (
3/2) (l1 – l4) (l2 – l4) (l3 – l4) l4 ^ (
3/2)), (4096 (l1 + l2) (l1 + l3) (l2 + l3) (l1 + l4) (l2 +
l4) (l3 + l4)) / ((l1 ^ 2 + 6 l1 l2 + l2 ^ 2) (l1 ^ 2 + 6 l1 l3 +
l3 ^ 2) (l2 ^ 2 + 6 l2 l3 + l3 ^ 2) (l1 ^ 2 + 6 l1 l4 + l4 ^ 2) (l2 ^ 2 +
6 12 14 + 14 2) (13 2 + 6 13 14 + 14 2)), ((11 + 12) (11 +
l3) (l2 + l3) (l1 + l4) (l2 + l4) (l3 + l4) (Log (l1) –
Log (l2)) ^ 2 (Log (l1) – Log (l3)) ^ 2 (Log (l2) –
Log (l3)) ^ 2 (Log (l1) – Log (l4)) ^ 2 (Log (l2) –
Log (l4)) ^ 2 (Log (l3) – Log (l4)) ^ 2) / (64 (l1 – l2) ^ 2 (l1 –
l3) ^ 2 (l2 – l3) ^ 2 (l1 – l4) ^ 2 (l2 – l4) ^ 2 (l3 – l4) ^ 2),
E ^ 6 (l1 / l2) ^ (l1 / (- l1 + l2)) (l1 / l3) ^ (
l1 / (- l1 + l3)) (l2 / l3) ^ (- 1 + l2 / (- l2 + l3)) (l1 / l4) ^ (
l1 / (- l1 + l4)) (l2 / l4) ^ (l2 / (- l2 + l4)) (l3 / l4) ^ (l3 / (- l3 + l4)) / (
l3 ^ 3 l4 ^ 3)}; t4 =
Compile ({a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, l1, l2,
l3, l4}, hair s3, CompilationTarget -> "C",
RuntimeAttributes -> {Listable}, Parallelization -> True); hw =
TimeUsed (); ay = 0; um = 0; U2 = {}; qv1 = array (0 &, 10); qv2 =
Array (0 & 10); sp2 = x /. Solve (x ^ (16) == x + 1, x) ((2)); To press(
N (sp2)); G = array (1, 15); Do(
G ((i)) = fraction (N (1/2 + i95 / sp2 ^ i)), {i, 1, 15}); G1 =
Take (G, {1, 12}). H1 = take (G, {13, 15}); Do(
Printing (i95); {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12} =
G1 {Pi, Pi / 2, Pi, Pi / 2, Pi, Pi / 2, Pi, Pi / 2, Pi, Pi / 2, Pi,
Pi / 2}; {l1, l2, l3, l4} = differences (Join ({0}, Sort (H1), {1}));
s4 = t4 (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, l1, l2,
13, 14); qv1 = qv1 + s4;
V = X (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
If (Re (Det (
Array slats (
Transpose(
Partition wall(
V.DiagonalMatrix ({l1, l2, l3, l4}). ConjugateTranspose (V), {2,
2})))))> 0, qv2 = qv2 + s4; ay = ay + 1);
If (Mod (i95, 1000000) == 0,
Print ({i95, ay, by, TimeUsed () – hw, "Probs", {ay / i95, N (ay / i95)},
qv2 / qv1}); hw = TimeUsed ();
Print ({(qv2 ((1)) / qv1 ((1))) / (8/33), (qv2 ((2)) / qv1 ((2))) / (25 /
341), (qv2 ((5)) / qv1 ((5))) / (1 – 256 / (27 Pi ^ 2))); {i95, ay, from,
qv1, qv2} >> OperatorMonotoneTwoQubitsCampusSave;
U2 = Join (U2, {{qv1, qv2}});
U2 >> OperatorMonotoneTwoQubitsCampusSave);
Label (eax) {i95, 16630332, 16630334};

Game Loop – Draw on screen from event handlers

If I have a traditional game loop like this:

while (true) {
    handleEvents(); // Executes any pending event handler
    clearScreen();
    update();
    draw();
}

How can I perform drawing operations in the event handlers? They are deleted. Should I call handleEvents() shortly after clearScreen? Normally, the event query is performed at the top of the game round.