Click here to Skip to main content
15,897,891 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Pictures in WebBrouser control Pin
Christian Graus20-May-07 19:56
protectorChristian Graus20-May-07 19:56 
QuestionV2.0 vs V3.0 Pin
Ray Cassick20-May-07 10:36
Ray Cassick20-May-07 10:36 
AnswerRe: V2.0 vs V3.0 Pin
Christian Graus20-May-07 11:03
protectorChristian Graus20-May-07 11:03 
GeneralRe: V2.0 vs V3.0 Pin
Ray Cassick20-May-07 11:15
Ray Cassick20-May-07 11:15 
GeneralRe: V2.0 vs V3.0 Pin
Christian Graus20-May-07 12:59
protectorChristian Graus20-May-07 12:59 
QuestionAdo.net with WPF (.Net Framework 3.0) xaml browser application Pin
Nada Adel19-May-07 7:23
Nada Adel19-May-07 7:23 
AnswerRe: Ado.net with WPF (.Net Framework 3.0) xaml browser application Pin
Paul Conrad14-Jul-07 6:52
professionalPaul Conrad14-Jul-07 6:52 
QuestionDetecting if a folder is being copied to... Pin
Christoff91517-May-07 11:17
Christoff91517-May-07 11:17 
Hello,

This relates to my question yesterday, but this question is far more specific so I figured it best to start a new thread regarding it.

I am currently trying to design a method that will detect whether or not a folder is being actively copied to once it is detected by my application. For my program to function correctly, any detected folders in the target directory MUST be finished being copied to before my program can pick them up for processing. However, no matter what I try, my program tries to grab the folders and move them for processing before the copy is actually finished.

So far I've tried checking the LastWriteTime and LastAccessTime of the directory via the DirectoryInfo class. For some reason, these properties would state that the last write and access times were x seconds ago, even when the files were not completely done copying.

I thought this might be caused by files being written to subfolders inside the folder I was checking (which I'm assuming are not checked in reference to that particular top folder), so on a suggestion from Christian Graus, I tried a recursive script that would get the size of all files and folders inside the target folder and return that value. My program would use this method to first get the size of the folder, sleep the thread for a second, then recheck the value. If the values matched, the folder would be processed. If they didn't match, the folder was passed over and checked on the next cycle. However, even though the files were still not done copying (the file copy progress box was still showing), the cumulative directory size would be reported as the same on both checks and it would pick up the folder early again. I also checked the reported size value against the actual size of the folder (though the properties window in Windows) and the reported size matched the actual directory size, even though my program got that value while the files were still actively copying (once again, the file copy progress dialog was still visible and progressing).

So I'm really at a loss here. Does anyone know of a method to check a folder's activity and report whether files are still actually being copied to it? I've posted some of the relevant snippets, in case I just boffed my code and didn't realize it.

Thanks in advance for any assistance.

Code for getting folder size:
<br />
    public static class Utility<br />
    {<br />
        public static int GetSize(DirectoryInfo dir)<br />
        {<br />
            int size = 0;<br />
            foreach (FileInfo f in dir.GetFiles())<br />
            {<br />
                size += (int)f.Length;<br />
            }<br />
            foreach (DirectoryInfo d in dir.GetDirectories())<br />
            {<br />
                size += GetSize(d);<br />
            }<br />
            return size;<br />
        }<br />
    }<br />


Code for scraping the target directory and checking whether a folder is done being copied to or not (code relevant to this issue is bolded):
<br />
//handler for BackgroundWorker doing the scraping<br />
void RunAsyncScrape(object sender, DoWorkEventArgs e)<br />
{<br />
    DirectoryInfo[] studies;<br />
    //attempt to search the directory<br />
    try<br />
    {<br />
        studies = new DirectoryInfo(targetdir).GetDirectories();<br />
    }<br />
    catch (Exception ex)<br />
    {<br />
        MessageBox.Show("Could not scrape the target directory\nReason: " + ex.Message, "File Scraping Error");<br />
    }<br />
<br />
    //if subdirectories are found, get the filepaths for all directories that<br />
    //have are fully copied and return them in an arraylist.<br />
    if (studies.Length > 0)<br />
    {<br />
        ArrayList orders = new ArrayList();<br />
        foreach (DirectoryInfo dir in studies)<br />
        {<br />
            int size = Utility.GetSize(dir);<br />
            Thread.Sleep(1000);<br />
            int sizeb = Utility.GetSize(dir);<br />
            if (size == sizeb)<br />
            {<br />
                //study is completely copied, move for processing<br />
		orders.Add(dir)<br />
            }<br />
        }<br />
        if (orders.Count > 0)<br />
            e.Result = orders;<br />
    }<br />
}<br />

AnswerRe: Detecting if a folder is being copied to... Pin
Dave Kreskowiak17-May-07 11:33
mveDave Kreskowiak17-May-07 11:33 
GeneralRe: Detecting if a folder is being copied to... Pin
Christoff91517-May-07 13:48
Christoff91517-May-07 13:48 
AnswerRe: Detecting if a folder is being copied to... Pin
kubben18-May-07 5:58
kubben18-May-07 5:58 
GeneralRe: Detecting if a folder is being copied to... Pin
Dave Kreskowiak18-May-07 9:58
mveDave Kreskowiak18-May-07 9:58 
GeneralRe: Detecting if a folder is being copied to... Pin
kubben18-May-07 11:50
kubben18-May-07 11:50 
GeneralRe: Detecting if a folder is being copied to... Pin
Christoff91518-May-07 12:16
Christoff91518-May-07 12:16 
GeneralRe: Detecting if a folder is being copied to... Pin
Dave Kreskowiak18-May-07 12:54
mveDave Kreskowiak18-May-07 12:54 
AnswerRe: Detecting if a folder is being copied to... Pin
Vasudevan Deepak Kumar23-May-07 4:32
Vasudevan Deepak Kumar23-May-07 4:32 
QuestionDoubt on Serialization Pin
meeram39517-May-07 3:18
meeram39517-May-07 3:18 
AnswerRe: Doubt on Serialization Pin
kubben17-May-07 6:14
kubben17-May-07 6:14 
AnswerRe: Doubt on Serialization Pin
Not Active17-May-07 8:00
mentorNot Active17-May-07 8:00 
AnswerRe: Doubt on Serialization Pin
Scott Dorman19-May-07 5:24
professionalScott Dorman19-May-07 5:24 
AnswerRe: Doubt on Serialization Pin
GgAben22-May-07 0:24
GgAben22-May-07 0:24 
Question.NET Enterprise Library Pin
Bommannan.Ramalingam16-May-07 22:50
Bommannan.Ramalingam16-May-07 22:50 
AnswerRe: .NET Enterprise Library Pin
Not Active17-May-07 8:07
mentorNot Active17-May-07 8:07 
QuestionPrinters in WPF Pin
jjholt16-May-07 14:32
jjholt16-May-07 14:32 
AnswerRe: Printers in WPF Pin
Paul Conrad14-Jul-07 6:51
professionalPaul Conrad14-Jul-07 6:51 

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.