<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d6566853\x26blogName\x3d1%25+inspiration\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://patke.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://patke.blogspot.com/\x26vt\x3d8220196945898414734', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>
Archives
Subscribe


Thursday, August 05, 2004

In todays techie tidbit post...

I am trying to ftp a file into a directory. BUT, once the file is in the directroy, it needs to be moved to another directory. Unfortunately, the move cannot occur until the upload process has completed. This code provides the check necessary to ensure that the file has finished uploading.

protected void pauseUntilCreated(string file)
{
bool created = false;

int i = 0;
while( ! created && i<60) //30 seconds max.
{
try
{
//try to open the file exclusively. If the open fails, it is
//still being written.
using (FileStream sw = File.OpenRead(file)) {created = true;}
}
catch(System.IO.IOException)
{
Console.WriteLine("Loading file: " + file);
Thread.Sleep(500); //sleep for one half second.
++i;
//not loaded yet. continue...
}
}

Not really happy with it since it uses exceptions for processing - which is slow - but don't see a way around it. Any ideas?

Permalink
Comments: Post a Comment