<repo_name>pratikalladi/candylibrary<file_sep>/log.md


### Week One: 
1.  [Dropfolder](https://github.com/yxie21/library/blob/master/DropFolder.java)

We start off with a simple scenario,

- ##### Context:

In the folder "folder," you enter two more levels of subfolders before being able to reach individual files ending with ".txt"

- ##### Goal:

Drag out all of the files ending with txt to the big folder. 

2. [Dropfolder.2]

- ##### Problem:

Right now, the line putting in the *folderpath* and the *document ending (.txt)* are hard codes.
When other people want to run it, they have to change these two configurations. In order to do so,
they have to use Eclipse. However, for the average users with zero programming experience, this could be
a very difficult task (also for users without programming software). 

- ##### Change made:

Therefore, I used *config.txt* to save all of the configurations and used HashMap (keys and values) to read the input configurations.
In this way, the users simply have to change the configurations in the txt file, which is easy for everyone.

- ##### An additional change:

By getting the location of config.txt in the first few lines of code through the relative path, users no longer have to worry about the exact location of the file. 


- ##### why use map?

###### 1. Retrieving values from the input key is very convenient.
###### 2. When there are a lot of configurations later on, map can be very time-efficient (changing O(N) to O(1)).

<file_sep>/src/main/java/Individual/Myfolder/Filetype.java
package Individual.Myfolder;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;

public class Filetype {
	
	public HashSet<String> type(String folderPath) {
		

	File[] list = new File(folderPath).listFiles();
	
	ArrayList<String> types = new ArrayList<String>();
	if(list!=null) {
	

	
	
	ArrayList<String> folderlocations = new ArrayList<String>();
	
	
	for (File file : list) {

		if (!file.getName().contains(".")) {
			String temp = folderPath + File.separator + file.getName();
			System.out.println(file.getName());
			System.out.println(file.getName()+" "+temp);
			folderlocations.add(temp);
			HashSet <String> newtypes= type(temp);
			for( String a: newtypes) {
				
				types.add(a);
				
			}
			

		}
		
		else {
			if(file.getName().startsWith(".")) {
				continue;
			}
			int index= file.getName().lastIndexOf(".");
			String ending= file.getName().substring(index);
			if(ending!=".DS_Store") {
				types.add(ending);
				}
			
		}

	}

}
	
	HashSet<String> myset= new HashSet<String>(types);
	return myset;
	

	}	
}	
<file_sep>/weeklylog.md


### Week One: 
1.  

We start off with a simple scenario,

- ##### Context:

In the folder "folder," you enter two more levels of subfolders before being able to reach individual files ending with ".txt"

- ##### Goal:

Drag out all of the files ending with txt to the big folder. 

2. [Dropfolder.2]

- ##### Problem:

Right now, the line putting in the *folderpath* and the *document ending (.txt)* are hard codes.
When other people want to run it, they have to change these two configurations. In order to do so,
they have to use Eclipse. However, for the average users with zero programming experience, this could be
a very difficult task (also for users without programming software). 

- ##### Change made:

Therefore, I used *config.txt* to save all of the configurations and used HashMap (keys and values) to read the input configurations.
In this way, the users simply have to change the configurations in the txt file, which is easy for everyone.

- ##### An additional change:

By getting the location of config.txt in the first few lines of code through the relative path, users no longer have to worry about the exact location of the file. 


- ##### why use map?

###### 1. Retrieving values from the input key is very convenient.
###### 2. When there are a lot of configurations later on, map can be very time-efficient (changing O(N) to O(1)).



### Week Two:

1. 

- ##### Context:

Sometimes, when users move the files around, it is easy to cause confusion and delete some important files during the process.

- ##### Goal:

Generate report for the original folder and the folder after the user does some manipulations on it to check if they are consistent (if there
are important files missing)

- ##### Special feature

To distinguish among the reports generated at different times, the output file includes the exact time at which the report is created. 

<file_sep>/src/main/java/Individual/Myfolder/Simplifier.java
package Individual.Myfolder;

import java.io.File;
import java.util.ArrayList;

public class Simplifier {

	public void simplify(String folderPath) {
		
		File[] list = new File(folderPath).listFiles();
	
		ArrayList<String> filepaths = new ArrayList<String>();
		
		ArrayList<String> folderlocations = new ArrayList<String>();

		for (File file : list) {

			if (!file.getName().contains(".")) {
				String temp = folderPath + File.separator + file.getName();
				folderlocations.add(temp);
				simplify(temp);
 
			} else {
				String temp2 = file.getName();
				filepaths.add(temp2);

			}

		}

		for (String a : folderlocations) {
			
			File getfile = new File(a);
			getfile.delete();

		}
		
         int lastindex= folderPath.lastIndexOf(File.separator);
   
         
		 String upperfolder= folderPath.substring(0, lastindex);
		
		 
		 for (String b: filepaths) {
			 if(b.startsWith(".")) {
				 continue;
			 }
			 File file= new File(b);
			 System.out.println(b+ "  "+ upperfolder+ File.separator+b );
			 file.renameTo(new File (upperfolder+ File.separator+b ));
		 }
		 
	}

}
<file_sep>/src/main/java/Individual/Myfolder/Ziphelp.java
package Individual.Myfolder;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Ziphelp {

	    public void ziphelp(String folderPath) {
	    	
	    
	      // 文件存放位置
	        String zipPath = "/Users/yuxinxie/Desktop/special.zip";
	        File zipFile = new File(zipPath);
	        String descDir = "/Users/yuxinxie/Desktop/";
	        boolean flag = unZip(zipFile, descDir);
	        System.out.println("解压成功还是失败=" + flag);
	    }
	/**
	     * 解压zip文件
	     *
	     * @param zipFile目标文件
	     * @param descDir解压后存放的位置
	     * @return true/false
	     */
	    public static boolean unZip(File zipFile, String descDir) {
	        boolean flag = false;
	        File pathFile = new File(descDir);
	        if (!pathFile.exists()) {
	            pathFile.mkdirs();
	        }
	        ZipFile zip = null;
	        try {
	            // 指定编码，否则压缩包里面不能有中文目录
	            zip = new ZipFile(zipFile, Charset.forName("gbk"));
	            for (Enumeration entries = zip.entries(); entries.hasMoreElements();) {
	                ZipEntry entry = (ZipEntry) entries.nextElement();
	                String zipEntryName = entry.getName();
	                InputStream in = zip.getInputStream(entry);
	                String outPath = (descDir + zipEntryName).replace("/",
	                        File.separator);
	                // 判断路径是否存在,不存在则创建文件路径
	                File file = new File(outPath.substring(0,
	                        outPath.lastIndexOf(File.separator)));
	                if (!file.exists()) {
	                    file.mkdirs();
	                }
	                // 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
	                if (new File(outPath).isDirectory()) {
	                    continue;
	                }
	 
	                OutputStream out = new FileOutputStream(outPath);
	                byte[] buf1 = new byte[2048];
	                int len;
	                while ((len = in.read(buf1)) > 0) {
	                    out.write(buf1, 0, len);
	                }
	                in.close();
	                out.close();
	            }
	            flag = true;
	            // 必须关闭，否则无法删除该zip文件
	            zip.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return flag;
	    }
	 
	}<file_sep>/README.md
# Folder Project

### Objective: 
We usually encounter a lot of unncessary troubles when dealing with folders with a lot of subfolders in our lives, so this Java project saves users time and effort when dealing with files in folders. 

### Functions: 

1. Drag out all of the files with the same ending (ex. ".txt", ".java") from a folder (including from the subfolders within the folder) and place them under the main folder 

2. Generate reports of the original folder and the modified folder for users to check if there is any error in the process of moving files around. 

3. Simplify the path length. Sometimes, a file is under a chain of subfolders (ex. subfolder A-- subfolder B--- subfolder C--- file). Delete the unnecessary subfolders and shorten the pathlength to get the file. 

4. The program can be generalized to any amount of subfolders now (an improvement from before)

5. Convert all of the jpg files to png files automatically. (similar conversion can happen for other such changes)

6. Users now have two options
##### - if grouptogether=yes, then files of the same suffix would be grouped together and placed in newly created folders (using their suffix) under the main folder (ex. all of the jpg files under subfolder jpg)
##### - if grouptogether=no, then all of the indiviual files would simply be dragged out to the main folder. 


### Functions to Develop 

1. When there are two files with the same name in the folder, rename them with different suffixes to distinguish them. 



