Could do with some help with this question.I am using the system.io, and I have to do things which require files to be moved, grouped, renamed. .
Working in command line application using c# so far I have moved some files from one directory to another, I now need to group some pdf files like so – B-12345 1.pdf, B-12345 2.pdf, B-12345 3.pdf, B-12345 4.pdf.I have been told I dont need to physically group them together just for the purposes of ensuring I only create one job per project reference(b-1234).
To give you a bit of background info on what im doing after these files are grouped I need to create a record in the job table sql database.But thats another question for another day just thought id give you some more info.
Mainly I just need info on how to read files that are in a file directory and grouping files, this would be very beneficial to me.?
To make the question a bit clearer this is the order in tasks should be done in the command line app.
- Read files in directory (I have moved them so unsure on this?)
- Group by project no (unsure)
- Create job record in sql db
- Move and rename file to correct location
Thanks in advance
My code is below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
public class MoveForProcessing
{
static void Main()
{
// move cad jobs to processing directory and delete former folder, use the System.IO.Path class.
System.IO.Directory.Move(@"C:\Users\Ben\My Documents\Temp\", @"C:\Users\Ben\My Documents\Processing\");
}
}
You could first declare a DirectoryInfo class of the dirctory in question
Then get an array of FileInfo objects for each file in the directory
You could also put a wildcard string into GetFiles() if you want only certain file types
Then you can increment through the array doing whatever you need with each FileInfo object