It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to make software that groups pictures into folders by date actually taken. The pictures will sort into folders with names the year taken like:
Folder: 2000
Inside the folder: Some pictures taken in the 2000.
How can I do that?
To get the date the picture was actually taken, you want to look at the Exif data.
This data is automatically read into the PropertyItems array when you use Image.FromFile(). You can then use another reference (like this one) to get the right codes for date info. You could also use this library to simplify reading the codes.
Not all images will have Exif data, so you may want to incorporate David's answer as a fallback.
Once you have the relevant date info, you can use Directory.Create(year) and File.Move(oldPath, newPath) to organize the files.
List<string> imageFiles= ... // Here you get the image path
Dictionary<int, List<string>> groupedPaths= ... //output dict
foreach(string str in imageFiles)
{
FileInfo fi=new FileInfo(str);
int year = fi.CreationTime.Year;
if(!groupedPath.ContainsKey(year))
{
var list=new List<string>();
list.Add(year, string);
groupedPaths.Add(year, list);
}
else
{
groupedPaths[year].Add(year, str);
}
//Now you can process with foreach or use LINQ to group your images
foreach(KeyValuePair<int, string> pair in groupedPaths)
{
...
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How to load string from a txt file to the listView?
I have a txt file with three lines of characters.
I read the first line of a txt file into the first row in listView and etc.?
Well if your line contains everything you need and doesn't need to be split after you can use ListBox instead of ListView
foreach(string line in File.ReadAllLines(pathToYourFile))
ListBox.Items.Add(line);
Or if you really need ListView you can use
foreach(string line in File.ReadAllLines(pathToYourFile))
listView.Items.Add(new ListViewItem(line));
Use iostreamreader .. then use readline function .. then fill the listview
Try something like this:
string[] lines = System.IO.File.ReadAllLines(#"yourtextfile");
foreach (string line in lines)
{
listView1.Items.Add(line);
}
Here is a Linq example for you.
using System.Linq;
...
System.IO.File.ReadAllLines(pathToFile)
.ToList()
.ForEach(line => listView.Items.Add(new ListViewItem(line)));
First,
using System.IO; <-- to read the file
Then, if you can use a listbox, addrange works well without the loop:
listBox1.Items.Clear();
string[] s_array = File.ReadAllLines( -- your file path -- );
listBox1.Items.AddRange(s_array);
If you're using a list view, then the loop suggested by Blablablaster above works well
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
It has soon been 12h of trying this and I can't get it to work. I have read all the threads I can find and nothing helps. I have tried to fiddle around with Excel Wrapper as well but it doesn't work. I'm new to C# and I'm trying to do a bullshit generator. What I am trying to do is reading a bunch of words from A1-A5, B1-B5 and C1-C5 in an .xlsx-file and putting them together in a textbox (I'm using Visual Studio) when clicking a button.
If anyone reads this and could give me a hint it would be much appreciated. Thanks in advance.
First you should pull the info from the xls doc to a collection (array, list, etc...)
The code for this should be easy to find online.
You are also going to need a random number generator:
Random rnd = new Random();
Then you are going to have the button click event select 2 random numbers, one for row and one for column, from your collection (2D array in this case):
int row_max = stuff[][].GetLength(0);
int col_max = stuff[][].GetLength(1);
int row = rnd.Next(0, row_max-1)
int col = rnd.Next(0, col_max-1); //between 0 and the number of columns
textbox1.text = textbox1.text + stuff[row][col].ToString();
This is indicative only, but all the parts of this can be easily googled.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
H iguys. I have a loop which parse users id's and adds tham to txt file.
What's the best way than to check if this txt has this id skip it ( while next parsing ).
The size of txt rises from 5-..... mb
I tried to add ids to List, but when the size of file if bigger than 5mb the app begins hanging
Use a HashSet<int> or HashSet<string>, collect the ids in it, then at the end write the result to the text file.
PS: Note that HashSet is O(1) while List is O(n)
You should probably load all of the IDs in the text file into some collection and check if that collection contains the IDs.
I honestly don't think that there's a much more efficient way of doing it than that.
A rule of thumb I believe is to trade time with space. If you want to make copying faster and avoid looking into the file again and again then you may maintain an array or linked list or hash table which also have the id stored in it
var userIsAlreadyThere = File.ReadLines(path).Contains(userid);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to create a folder automatically when a solution is installed in the computer i.e( Local Disk:D) using c# windows forms?
Solution#1:
On first run of the application (make an xml file to track the first execution) you may create folder.
Solution#2: (Good one)
You may check if that directory exists ,if not then create the directory
try
{
// If the directory doesn't exist, create it.
if (!Directory.Exists(palettesPath))
{
Directory.CreateDirectory(palettesPath);
}
}
catch (Exception)
{
// Fail silently
}
Source:
check this link
How to Add Items to a Deployment Project
http://msdn.microsoft.com/en-us/library/z11b431t.aspx
Specifically:
How to: Add and Remove Folders in the File System Editor
http://msdn.microsoft.com/en-us/library/x56s4w8x.aspx
See the MSDN for more info, but the gist is:
You set the path like either of the ways below. See string literals for more info on this:
string newPath = #"c:\yourpath";
or
string newPath = "c:\\yourpath\\morepath";
To create the directory, you use this:
System.IO.Directory.CreateDirectory(newPath);
Hope this helps!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm working on something like recycle bin, that I need to move folder/files to already existing folder, I tried to use
Directory.Move
but it creates new directory and that's wrong for me, I have a specific directory to move to.
Can you help me?
It seems do don't actually want to move the folder, you want to move the contents of the folder. If you want to do that, you have to tell the computer to do that:
void MoveContentsOfDirectory(string source, string target)
{
foreach (var file in Directory.EnumerateFiles(source))
{
var dest = Path.Combine(target, Path.GetFileName(file));
File.Move(file, dest);
}
foreach (var dir in Directory.EnumerateDirectories(source))
{
var dest = Path.Combine(target, Path.GetFileName(dir));
Directory.Move(dir, dest);
}
// optional
Directory.Delete(source);
}