Click here to Skip to main content
15,913,854 members
Home / Discussions / C#
   

C#

 
QuestionDebug Statements - writing to the console and files Pin
stormydaniels18-Nov-08 4:18
stormydaniels18-Nov-08 4:18 
AnswerRe: Debug Statements - writing to the console and files Pin
DaveyM6918-Nov-08 4:27
professionalDaveyM6918-Nov-08 4:27 
GeneralRe: Debug Statements - writing to the console and files Pin
Ennis Ray Lynch, Jr.18-Nov-08 4:41
Ennis Ray Lynch, Jr.18-Nov-08 4:41 
AnswerRe: Debug Statements - writing to the console and files [modified] Pin
Paul Conrad18-Nov-08 4:54
professionalPaul Conrad18-Nov-08 4:54 
GeneralRe: Debug Statements - writing to the console and files Pin
Dave Kreskowiak18-Nov-08 8:10
mveDave Kreskowiak18-Nov-08 8:10 
GeneralRe: Debug Statements - writing to the console and files Pin
Paul Conrad18-Nov-08 8:39
professionalPaul Conrad18-Nov-08 8:39 
GeneralRe: Debug Statements - writing to the console and files Pin
stormydaniels18-Nov-08 5:24
stormydaniels18-Nov-08 5:24 
QuestionDirectory.GetLastWriteTime(fpath) overwrites the path string Pin
beriho18-Nov-08 4:05
beriho18-Nov-08 4:05 
Hi,

I am trying to write a code that gets all the files in a folder and returns the name of the file that has the most recent "write" date.

i have wrote this function that gets "path" and should return fileName string.

string[] fileNames = Directory.GetFiles(filePath); // get file names in array

string[] fileDatesList = fileNames; // create fileDateList and initialze(not relevant with what

for (int i = 0; i < fileNames.Length; i++)
{
fileDatesList[i] = Directory.GetLastWriteTime(fileNames[i]).ToString();

}

//TODO write the return(

my problem is with this line:
fileDatesList[i] = Directory.GetLastWriteTime(fileNames[i]).ToString();

lets say i have 3 files in a folder:
abc00, abc01, abc02.

fileNames string array gets all 3 names and stores them.
when i get to the fileDatesList in the for loop, all the entities in
fileNames array are CHANGED with the Date of the file...

example:
before for loop:
fileNames=[abc00,abc01,abc02]
fileDatesList=[abc00,abc01,abc02]
step i=0:
fileNames=[18/11/2008 4:25PM,abc01,abc02]
fileDatesList=[18/11/2008 4:25PM,abc01,abc02]

and so on untill both have only date and time...

i don't understand why it does that Smile | :) why it changes fileNames while changing fileDatesList... although i am not assigning fileDatesList to fileNames in anywhere out of the getLastWriteTime...

thanks a lot!

May The Force Be With You...
AnswerRe: Directory.GetLastWriteTime(fpath) overwrites the path string Pin
Ennis Ray Lynch, Jr.18-Nov-08 4:09
Ennis Ray Lynch, Jr.18-Nov-08 4:09 
GeneralRe: Directory.GetLastWriteTime(fpath) overwrites the path string Pin
beriho18-Nov-08 4:13
beriho18-Nov-08 4:13 
AnswerRe: Directory.GetLastWriteTime(fpath) overwrites the path string Pin
Guffa18-Nov-08 4:12
Guffa18-Nov-08 4:12 
GeneralRe: Directory.GetLastWriteTime(fpath) overwrites the path string Pin
beriho18-Nov-08 5:03
beriho18-Nov-08 5:03 
QuestionLearning C# by example? Complete projects? Pin
Dougmeister18-Nov-08 3:04
Dougmeister18-Nov-08 3:04 
AnswerRe: Learning C# by example? Complete projects? Pin
Alan Balkany18-Nov-08 3:27
Alan Balkany18-Nov-08 3:27 
AnswerRe: Learning C# by example? Complete projects? Pin
#realJSOP18-Nov-08 3:44
professional#realJSOP18-Nov-08 3:44 
GeneralRe: Learning C# by example? Complete projects? Pin
Dougmeister18-Nov-08 3:51
Dougmeister18-Nov-08 3:51 
GeneralRe: Learning C# by example? Complete projects? Pin
stormydaniels18-Nov-08 4:11
stormydaniels18-Nov-08 4:11 
GeneralRe: Learning C# by example? Complete projects? [modified] Pin
Guffa18-Nov-08 4:19
Guffa18-Nov-08 4:19 
GeneralRe: Learning C# by example? Complete projects? Pin
#realJSOP18-Nov-08 4:31
professional#realJSOP18-Nov-08 4:31 
GeneralRe: Learning C# by example? Complete projects? Pin
stormydaniels18-Nov-08 5:22
stormydaniels18-Nov-08 5:22 
GeneralRe: Learning C# by example? Complete projects? Pin
Dougmeister19-Nov-08 2:07
Dougmeister19-Nov-08 2:07 
AnswerRe: Learning C# by example? Complete projects? Pin
Priya Prk18-Nov-08 9:47
Priya Prk18-Nov-08 9:47 
Questionscreensaver Pin
jugal_piet@indiatimes.com18-Nov-08 2:13
jugal_piet@indiatimes.com18-Nov-08 2:13 
AnswerRe: screensaver Pin
SeMartens18-Nov-08 2:18
SeMartens18-Nov-08 2:18 
JokeRe: screensaver Pin
Giorgi Dalakishvili18-Nov-08 2:28
mentorGiorgi Dalakishvili18-Nov-08 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.