# I need help please (process pictures from a folder)

**URL:** <https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 29, 2023, 1:05am UTC](https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341 "2023-11-29T01:05:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yanina](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@Yanina](https://discourse.processing.org/u/Yanina)\
**Post date:** [November 29, 2023, 1:05am UTC](https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341/1 "2023-11-29T01:05:34Z")

</div>

Hello everybody! I am writing code that processes pictures into letters and I have a problem that the program does not consistently process pictures from a folder even though they are numbered (initially this is a video that was translated into png) tell me how to make it so that it processes them in order and it works finally the right video)

```auto
File dir;
File [] files;
int letters = 4;
int rows = 100;
float letterWidth = 256.0/letters;
int bounding = 4;

PImage img;
PShape[] textArray = new PShape[letters];
int frame = 0;

 
 void setup() {
 size(720, 1280);
 noStroke();
 dir = new File(dataPath(""));
 files = dir.listFiles();
 println("Найдено файлов: " + files.length );

 for (int i =0; i<letters; i++) { 
 textArray[i] = loadShape("..//svg//s//"+nf(i+1, 2)+".svg");
 }
 colorMode(HSB);
}
 
void draw() {
 background(250);
 loop();
 if (frame < files.length && files[frame].isFile()) {
 String path = files[frame].getAbsolutePath();
 img = loadImage(path);
 println(" Название кадра: " + frame );
 
 for (int y = height/rows/2; y < img.height; y=y+height/rows ) {
 int x1=0, x2=0;
 int lNum=-1, lNumPre = -1;
 
 
 for (int x = 0; x < img.width; x++) {
 int loc = x + y*img.width;
 float r;
 r = red(img.pixels[loc]);
 if (r>2) {
 lNum = floor(r/letterWidth);
 } else {
 lNum = -1;
 }

 if (lNum != lNumPre ) {
 x2=x;
 printLetter( x1, x2, y, lNumPre);
 x1=x2;
 lNumPre = lNum;
 } else {
 x2=x;
 if (x == width-1) {
 printLetter( x1, x2, y, lNumPre);
 }
 }
 }
 }
 saveFrame("data-out/text-#####.png");
 } else {
 exit();
 }
 frame++;
}

void printLetter(int x1, int x2, int y, int lNum) { 
 if (abs(x2-x1)>bounding*2) {
 lNum = constrain(lNum,0,letters-1);
 //textArray[lNum].disableStyle();
 fill(lNum*letterWidth, 128, 128);
 shape(textArray[lNum], x1+bounding, y-height/rows/2+bounding, abs(x2-x1)-bounding, height/rows-bounding);
 }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 29, 2023, 3:14am UTC](https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341/2 "2023-11-29T03:14:25Z")

</div>

Not providing an answer but I would like to ask you to post code (in future) using code tags.

To fix your opening post

1. Edit the post
2. Select all code
3. Click the button \</\>
4. Save the post

It makes it easier to read, easier to copy and it tells the forum software not to treat e.g. `[]` as .

[Edited]

---

<div class="post-metadata">

**Author:** ![sterretje](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sterretje](https://discourse.processing.org/u/sterretje)\
**Post date:** [November 29, 2023, 7:02am UTC](https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341/3 "2023-11-29T07:02:48Z")

</div>

@Chrisir, you missed the at the end of the last line 🤣

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 30, 2023, 7:53am UTC](https://discourse.processing.org/t/i-need-help-please-process-pictures-from-a-folder/43341/4 "2023-11-30T07:53:37Z")

</div>

Hello @Yanina,

The code was formatted for you by a member of our community.

For future reference:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

There may be something in here to help you:

> [@Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147):
>
> Summary (TL;DR) Ask complete questions to get better answers! Be specific. For example: I want to load an image. I tried using createImg() , and I expected the image to be on canvas, but what happened instead was the image showing up below the canvas. Isolate your problem and work in small steps. Share only the code directly related to your problem if it is part of a bigger project, and if something isn’t working, try the smallest code that could do the thing you want. Can we run your code to …

`:)`
