Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Feb 2007
Offline Last Active Sep 26 2014 12:39 AM

Topics I've Started

Simple pictures organizer in C#

17 September 2014 - 10:20 PM

Hi all,


I have way too many pictures on my PC and they are everywhere. I am sure many of you have same problem.

I am attempting to create a simple program to organize them a bit and minimizing manual work, but unfortunately there will still be some.


Please take a look through this code and let me know if you have any suggestions. I am not very happy with how different pictures with same name is handled. How can I improve this code?



//Start Execution here...
private void startBtn_Click(object sender, EventArgs e)
	DirectoryInfo di = new DirectoryInfo("C:\\srcPictures");

private void WalkDirectoryTree(System.IO.DirectoryInfo root)
	FileInfo[] files = null;
	DirectoryInfo[] subDirs = null;

	// First process files under root folder
	files = root.GetFiles("*.*");
	Logger("Processing Files under: " + root.FullName);

	if (files != null)
		foreach (FileInfo fi in files)
			string picTakenOn = getDateTaken(fi, false);
			string targetDir = "";

			if (picTakenOn.Contains("DATETAKEN"))
				picTakenOn = picTakenOn.Replace("DATETAKEN", "");
				targetDir = "C:\\organizedPictures\\" + picTakenOn + "\\";
				if (!Directory.Exists(targetDir))
				copyFileToDestination(fi, fi.FullName, targetDir + fi.Name);
			else if (picTakenOn.Contains("DATEMODIFIED"))
				picTakenOn = picTakenOn.Replace("DATEMODIFIED", "");
				targetDir = destDirectory.Text + "\\Sorted_DateModified\\" + picTakenOn + "\\";
				if (!Directory.Exists(targetDir))
				Logger("DATEMODIFIED used instead of DATETAKEN for: " + fi.FullName);
				copyFileToDestination(fi, fi.FullName, targetDir + fi.Name);
			else if (picTakenOn.Contains("INVALID"))
				Logger("Not an image (Skipped): " + fi.FullName);

		// Resursion for all subdirectories
		subDirs = root.GetDirectories();
		foreach (System.IO.DirectoryInfo dirInfo in subDirs)

private void copyFileToDestination(FileInfo srcInfo, string sourcePath, string destPath)
	if (File.Exists(destPath)) //Same file name already exists
		FileInfo destInfo = new FileInfo(destPath);
		if (srcInfo.Length != destInfo.Length) //If different images (check by filesize)
			Logger("FILENAME conflict for: " + sourcePath);
			copyFileToDestination(srcInfo, sourcePath, destPath + "_dup" + srcInfo.Extension);
			Logger("SKIPPED copy (Dup found) for: " + sourcePath);
		File.Copy(sourcePath, destPath);

private string getDateTaken(FileInfo fi, bool includeDate)
	if (fi.Extension != ".jpeg" && fi.Extension != ".jpg" && fi.Extension != ".JPEG" && fi.Extension != ".JPG")
		return "INVALID";

	Regex r = new Regex(":");

	FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
	Image myImage = Image.FromStream(fs, false, false);

		PropertyItem propItem = myImage.GetPropertyItem(36867); //36867 is for Date taken
		string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2).Split(' ')[0];
		return ("DATETAKEN" + dateTaken.Split('-')[0] + "-" + dateTaken.Split('-')[1]);
		string dateModified = fi.LastWriteTime.ToString();
		return ("DATEMODIFIED" + dateModified.Split(' ')[0].Split('/')[2] + "-" + dateModified.Split(' ')[0].Split('/')[1]);

public void Logger(String lines)
	//Set the log file
	string logFile = "C:\\organizedPictures\\log.txt";

	System.IO.StreamWriter file = new System.IO.StreamWriter(logFile, true);


got an interview with EA

10 March 2014 - 09:32 PM


I have got a phone interview with EA in couple days. For this job



My issue is that I have 2 years experience in Software testing and some development. But I have never worked on Games.. I did a openGL project in school but that's it.

I really want to this job and have always dreamed about working at EA.

Can someone give me any hints by looking at the description what I should concentrate on to prepare? thanks!

help with python - write class similar to defaultdict

31 October 2013 - 02:17 PM



Hi, I am new to python and trying to write a class similar to to the defaultdict class.

I am little stuck on the constructor. On the python website example they first create a the defaultdict object with type as parameter, and then fill it. Example d = defaultdict(list) and then input "key,value"


If I directly pass "s" when creating object, it seems to be fine, but how can I make it similar to how it's really implemented. Thanks for help!

class MyDictionary(dict): #Parent class is "dict"
    'This is a derived class from python dict'
    def __init__(self, default_factory=None): # implement the parameters correctly
        dict.__init__(self, default_factory)
        #self.default_factory = default_factory
    #def anotherMethod-ToDo-forexmaple-d[10],handle if key doesn't exist
s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
d = MyDictionary(list)
for k, v in s:
print (d.items())

simple char array, please help

26 June 2013 - 02:13 PM

Hi, I am trying to simple return a string but I get this error:

In function 'getNetworkAtPriority':

warning: function returns address of local variable
In function 'main':
error: incompatible types in assignment


Please help what I am doing wrong? thanks

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * getNetworkAtPriority( )
    char returnValue[14];
    sprintf( returnValue, "mcc-mnc-umts");
    return returnValue;

int main()
    char entry1[14];
    entry1 = getNetworkAtPriority( "1" );

    return 0;

Help split simple string in c

16 June 2013 - 05:17 PM


I have to split simple string in c.

char readLine[7]; //Get from a file, Examples: "001:330", "01:330", "01:33", "333:01"
char num1[3];
char num2[3];
//How can I get for example num1="001", num2="330"

I am not good with char manupalation. Please help me how I can split with delimiter ":"

I think should be easy since I know the line from file can be at most 7 characters, and in above format, so I don't need to do any other handling.


Thanks for your help!