Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision B : add opening function #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions pechakucha10x20/U_CheckFolder.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
ArrayList imageFiles = new ArrayList();
boolean folderIsSelected ;
int countSelection ;
String selectedPathFolder = ("") ;
// main void
//choice Folder
void choiceFolder() {
folderIsSelected = true ;
if(key =='o') selectFolder("Select a folder to process:", "folderSelected");
}



// check what's happen in the selected folder
void checkFolder() {
if(folderIsSelected && selectedPathFolder != ("") ) {
countSelection++ ;
imageFiles.clear() ;
String path = selectedPathFolder ;

println("Listing info about all files in a directory and all subdirectories: ");
ArrayList allFiles = listFilesRecursive(path);

String fileName = "";

for (int i = 0; i < allFiles.size(); i++) {
File f = (File) allFiles.get(i);
fileName = f.getName();
//println("Name: " + filename);
//println("Full path: " + f.getAbsolutePath());
//println("Is directory: " + f.isDirectory());

// Add it to the list if it's not a directory
if (f.isDirectory() == false) {
String lastThree = fileName.substring(fileName.length()-3, fileName.length());
if (lastThree.equals("PNG") || lastThree.equals("png") || lastThree.equals("JPG") || lastThree.equals("jpg") || lastThree.equals("GIF") || lastThree.equals("gif")) {
imageFiles.add(f);
}
}
}
// show the info name file
for (int i = 0; i < imageFiles.size(); i++) {
File f = (File) imageFiles.get(i);
println("Name: " + f.getName());
}

// to don't loop with this void
folderIsSelected = false ;
}
}
// end main void

//choice Folder
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
selectedPathFolder = selection.getAbsolutePath() ;
folderIsSelected = true ;
}
}

// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
}
else {
// If it's not a directory
return null;
}
}

// This function returns all the files in a directory as an array of File objects
// This is useful if you want more info about the file
File[] listFiles(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
File[] files = file.listFiles();
return files;
}
else {
// If it's not a directory
return null;
}
}

// Function to get a list ofall files in a directory and all subdirectories
ArrayList listFilesRecursive(String dir) {
ArrayList fileList = new ArrayList();
recurseDir(fileList, dir);
return fileList;
}

// Recursive function to traverse subdirectories
void recurseDir(ArrayList a, String dir) {
File file = new File(dir);
if (file.isDirectory()) {
// If you want to include directories in the list
a.add(file);
File[] subfiles = file.listFiles();
for (int i = 0; i < subfiles.length; i++) {
// Call this function on all files in this directory
recurseDir(a, subfiles[i].getAbsolutePath());
}
}
else {
a.add(file);
}
}
139 changes: 25 additions & 114 deletions pechakucha10x20/pechakucha10x20.pde
Original file line number Diff line number Diff line change
@@ -1,75 +1,33 @@

import java.io.File;

boolean start = true;

int lastSecond;
int thisImage = 0;

ArrayList imageFiles = new ArrayList();

// main source is from UCLA Arts Software Studio by Casey Reas
void setup() {
size(1024, 768);
lastSecond = second();
instruction() ;
}

String path = sketchPath;

println("\nListing info about all files in a directory and all subdirectories: ");
ArrayList allFiles = listFilesRecursive(path);

String fileName = "";

for (int i = 0; i < allFiles.size(); i++) {
File f = (File) allFiles.get(i);
fileName = f.getName();
//println("Name: " + filename);
//println("Full path: " + f.getAbsolutePath());
//println("Is directory: " + f.isDirectory());
PImage img;

// Add it to the list if it's not a directory
if (f.isDirectory() == false) {
String lastThree = fileName.substring(fileName.length()-3, fileName.length());
if (lastThree.equals("PNG") ||
lastThree.equals("png") ||
lastThree.equals("JPG") ||
lastThree.equals("jpg") ||
lastThree.equals("GIF") ||
lastThree.equals("gif")) {
void draw() {
checkFolder() ;
showPictures() ;
}
void keyPressed() {
choiceFolder() ;
}

imageFiles.add(f);
}
println(lastThree);
}
//println("Size: " + f.length());
//String lastModified = new Date(f.lastModified()).toString();
//println("Last Modified: " + lastModified);
println("-----------------------");
}

println("-----------------------");
println("-----------------------");
println("-----------------------");
println("-----------------------");
println("-----------------------");

for (int i = 0; i < imageFiles.size(); i++) {
File f = (File) imageFiles.get(i);
println("Name: " + f.getName());
}
// ANNEXE

lastSecond = second();

//line(0, 0, width, height);
//line(0, height, width, 0);
textAlign(CENTER);
background(255);
text("PRESS SPACEBAR TO START", width/2, height/2);
}

PImage img;
int lastSecond;
int thisImage = 0;
int countRef ;

void draw() {
void showPictures() {
if(countSelection != countRef) thisImage = 0 ;
// Empty, but needed to keep listening for keys
if (start && lastSecond != second() && second() % 20 == 0) {
if (!folderIsSelected && selectedPathFolder != ("") && lastSecond != second() && second() % 2 == 0) {
File f = (File) imageFiles.get(thisImage);
img = loadImage(f.getAbsolutePath());
if (thisImage < imageFiles.size()-1) {
Expand All @@ -78,63 +36,16 @@ void draw() {
image(img, 0, 0, width, height);
lastSecond = second();
}
countRef = countSelection ;
}

void keyPressed() {

if (key == ' ') {
start = true;
}
}

// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
}
else {
// If it's not a directory
return null;
}
}

// This function returns all the files in a directory as an array of File objects
// This is useful if you want more info about the file
File[] listFiles(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
File[] files = file.listFiles();
return files;
}
else {
// If it's not a directory
return null;
}
void instruction() {
textAlign(CENTER);
background(255);
fill(0) ;
text("PRESS 'O' TO SELECT FOLDER", width/2, height/2);
}

// Function to get a list ofall files in a directory and all subdirectories
ArrayList listFilesRecursive(String dir) {
ArrayList fileList = new ArrayList();
recurseDir(fileList, dir);
return fileList;
}

// Recursive function to traverse subdirectories
void recurseDir(ArrayList a, String dir) {
File file = new File(dir);
if (file.isDirectory()) {
// If you want to include directories in the list
a.add(file);
File[] subfiles = file.listFiles();
for (int i = 0; i < subfiles.length; i++) {
// Call this function on all files in this directory
recurseDir(a, subfiles[i].getAbsolutePath());
}
}
else {
a.add(file);
}
}