We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to copy a file to subdirectory /data/
Page Index Toggle Pages: 1
how to copy a file to subdirectory /data/ (Read 1914 times)
how to copy a file to subdirectory /data/
Jan 5th, 2010, 6:26am
 
i have made a sketch that when '1' is oressed on the keyboard it captures a video clip with 300 frames and 30fps  from webcam into a .mov file.

i need to then afterwards move this .mov file into a subdirectory called data.
this is needed because i then from this directory read all the files and show them using a python script.

if anyone can help me youre my heroes! Wink

kind regards antima55
ibeams.org
Re: how to copy a file to subdirectory /data/
Reply #1 - Jan 5th, 2010, 7:11am
 
Why not write the file directly at the right place Ah, I suppose to avoid reading unfinished movies, right
See Moving a File or Directory to Another Directory.
Re: how to copy a file to subdirectory /data/
Reply #2 - Jan 6th, 2010, 5:54am
 
thank you!!!

is it directly to be copied into my sketch or do i have to implement some strange library or something?
Re: how to copy a file to subdirectory /data/
Reply #3 - Jan 6th, 2010, 6:41am
 
Pure Java code like that can be used directly in Processing. Batteries included. Just adapt it to your needs.
Re: how to copy a file to subdirectory /data/
Reply #4 - Jan 7th, 2010, 4:15am
 
well i am sorry but i cant figure it out, here is my code:

void optag(){
 str2=""+cnt3+cnt2+cnt;
 mm = new MovieMaker(this, width, height, str2 +".mov",30, MovieMaker.H263, MovieMaker.HIGH);
       for(int i=0;i<100;i++){
         m.update();//update the camera view
         m.imageCopy(pixels);//draw image to stag
         updatePixels();
         mm.addFrame();
       }
       mm.finish();
       // File (or directory) to be moved
File file = new File("000");

// Destination directory
File dir = new File("data");

// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) {
   println("not moved");
}

 cnt=cnt+1;
 if(cnt>9){
   cnt=0;
   cnt2=cnt2+1;
   if(cnt2>9){
     cnt2=0;
     cnt3=cnt3+1;
   }
 }
   noLoop();
}


this function void optag (optag is danish for record) is called every time you press 1 on the numpad.
gives an output file named after 000,001,002,003,004,005 etc. .mov

i have a subdirectory in the sketch folder named data where i want to move to or even better copy to. and if needed overwrite is ok.
Re: how to copy a file to subdirectory /data/
Reply #5 - Jan 7th, 2010, 4:16am
 
btw the naming of the file to move would me 'str2 +".mov" ' or something
Re: how to copy a file to subdirectory /data/
Reply #6 - Jan 7th, 2010, 5:58am
 
antima55 wrote on Jan 7th, 2010, 4:15am:
File file = new File("000");

// Destination directory
File dir = new File("data");

"000" won't work because the file is named "000.mov"...
"data" won't work, because it is relative to the location of the class file, somewhere on your temp dir if running from the PDE... I suppose you would use absolute paths, not relative ones.

Note: you can use a single counter and format it with nf() to get leading zeroes...

So, I would write:
Code:
void optag(){
movieName = nf(cnt, 3) + ".mov";
mm = new MovieMaker(this, width, height, movieName ,30, MovieMaker.H263, MovieMaker.HIGH);
// [...]
mm.finish();
// File (or directory) to be moved
File file = saveFile(movieName);

// Destination file
File dest = new File(savePath("data"), movieName);


// Move file to new directory
boolean success = file.renameTo(dest);
if (!success) {
  println("not moved");
}

   cnt++;
 }
  noLoop();
}
(untested)
savePath and saveFile are not in the main reference but in the Developers Reference (PApplet page).
They give the path to the location of the sketch.

Quote:
even better copy to

Curiously, there is no built-in facility to copy files in Java, usual way is to open the file as read, open the dest file as write, and transfer bytes in a loop...
Re: how to copy a file to subdirectory /data/
Reply #7 - Jan 7th, 2010, 7:48am
 
to PhilHo

HEY IT WORKED!!!!!!!!!!

thank you so much for this help plus opening my eyes to general java.
i really want to pay back by crediting your help at my project site.
do you have a website or something?

kind regards
Re: how to copy a file to subdirectory /data/
Reply #8 - Jan 7th, 2010, 12:12pm
 
There is a WWW button on my messages... Smiley
Thanks!
Re: how to copy a file to subdirectory /data/
Reply #9 - Jan 8th, 2010, 2:40am
 
look up
http://ibeams.org/?page_id=619
and see your name Smiley
thanks again!!!
Page Index Toggle Pages: 1