CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Posts
    22

    Checking FileSize and Redirecting Large Files

    Hello,

    I am working on a new development tool that would impact Logon/Logoff times,
    as well as increase network bandwidth usage.

    Goal of the project is, for Windows 7, to create a tool that at logon checks the sizes of the files on the desktop and if the file reaches certain size, takes some action: whether warns the user to do something with these files or copies the files to a share Drive and creates desktop shortcuts.

    Was looking to do this with a form using C#. Before I begin was wondering if there were any examples out there of anything similiar to look at or any sample code of how to collect the filesizes and then move the larger files.

    Thank You for your help!

  2. #2
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Checking FileSize and Redirecting Large Files

    I don't know how deep is your c# or .net knowledge but this might help you:
    FileInfo.Length Property
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  3. #3
    Join Date
    Aug 2010
    Posts
    22

    Re: Checking FileSize and Redirecting Large Files

    Thank You for the Reply.

    This will help me get off to a great start.

  4. #4
    Join Date
    Aug 2010
    Posts
    22

    Re: Checking FileSize and Redirecting Large Files

    Hello,

    I have used the fileinfo.length method successfully.
    I have scanned my directory, displayed all filenames and file lengths.

    I now have one last task to Redirect any files that are > then a fixes length and Move them to a new folder on a Share Drive.

    I have all the logic in place that checks the filesize and tried using the fileinfo.MoveTo() Method.

    However found this to take my current files and move them to a directory but also rename them.

    Looking to just Move the file from its current directory into a new directory if it exceeds a size.

    Which method would work best for this?

    Thank You.

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Checking FileSize and Redirecting Large Files

    that's the way how the move method works. just use the same name so it does not get renamed.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    Aug 2010
    Posts
    22

    Re: Checking FileSize and Redirecting Large Files

    Yeah only problem is I have an array where it is locating multiple files from Directory A and if they exceed a certain size it is moving them to Directory B though.

    Think I got it though.

    DirectoryInfo di = new DirectoryInfo("C:\\OldFolder");

    FileInfo[] fiArr = di.GetFiles();

    foreach (FileInfo f in fiArr)
    {

    if (f.length > 10000 )
    {
    f.MoveTo(@"C:\NewFolder" + f.Name);
    }
    else....

    }

    Thinking this should do the trick.
    Last edited by TWDeveloper; December 10th, 2010 at 09:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured