http://imagej.273.s1.nabble.com/How-to-use-File-rename-path1-path2-to-move-files-in-same-directory-tp5000628p5000634.html
Thank you for your help.
Mat M. Al-Tamimi, MSc, DABR
On Nov 2, 2012, at 4:37 AM, "Straatman, Kees R. (Dr.)" <
> Dear Mat,
>
> The code below might do the job. Your file CreateDirectory and File.rename were wrong.
>
> //Get the directory where the QA Images reside
> dir = getDirectory("Choose a Directory ");
> SaveDir = getDirectory("Choose a Sort Save Directory ");
>
> //Create file list of the QA Images
> list = getFileList(dir);
> print("number of files in the Directory ="+ list.length);
>
> //Look throug the list - Create RI, RD and what ever folder and move the files to
> for (i=0; i<list.length; i++) {
> if (endsWith(list[i], "/")){
> //listFiles(""+SubDirNames[0]+list[i]);
> }else{
> //Split the Name by "." and look at the first Entry
> Data = split(list[i],".");
>
> // Make directory name
> DirName = Data[0];
>
> //Ceate that directory
> File.makeDirectory(SaveDir+File.separator+ DirName);
>
> // Move the file to that Dir
> File.rename(dir + list[i],SaveDir + DirName + File.separator + list[i]);
>
> }
> }
>
>
> Best wishes
>
> Kees
>
>
> Dr Ir K.R. Straatman
> Senior Experimental Officer
> Centre for Core Biotechnology Services
> University of Leicester, UK
>
http://www.le.ac.uk/biochem/microscopy/home.html>
> ImageJ workshops 17-18 December 2012-11-02:
http://www.le.ac.uk/biochem/microscopy/ImageJ2012.html>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Mat M Al-Tamimi
> Sent: 01 November 2012 21:29
> To:
[hidden email]
> Subject: How to use File.rename(path1,path2) to move files in same directory
>
> Hi
>
> I am working on a project that have large number of files in one directory (Images and other files all dicom).
> The file names start with RI or RT or RP indicating image treatment and plan. I want to extract the image files only to analyze them. So I wrote the following code to sort them into DIR's:
>
> //Get the directory where the QA Images reside
> dir = getDirectory("Choose a Directory ");
> SaveDir = getDirectory("Choose a Sort Save Directory ");
>
> //Create file list of the QA Images
> list = getFileList(dir);
> print("number of files in the Directory ="+ list.length);
>
> //Look throug the list - Create RI, RD and what ever folder and move the files to
> for (i=0; i<list.length; i++) {
> if (endsWith(list[i], "/")){
> listFiles(""+SubDirNames[0]+list[i]);
> }else{
> //Split the Name by "." and look at the first Entry
> Data = split(list[i],".");
>
> // Make directory name
> DirName = Data[0];
>
> //Ceate that directory
> CreateDirectory(SaveDir, DirName);
>
> // Move the file to that Dir
> File.rename(SaveDir + list[i],SaveDir + DirName + File.separator + list[i]);
>
> }
> }
>
>
> The directory gets created but the file does not get moved into the directory with the File.rename returning 1.
> Do anyone know why?? Or what I am doing wrong??
>
> Mat M. AL-Tamimi
>
[hidden email]
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html