Copy all Files in Directories and Subdirectories in C#

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 45

  • @willdelarosa4290
    @willdelarosa4290 3 ปีที่แล้ว +1

    Waaoooo por fin entendí cómo copiar recursivamente y entendí el concepto "recursivamente" en sí.
    Finally I understood how recursively copy and understood the meaning of the word "recursively" itself.

  • @ievheniiierokhin1677
    @ievheniiierokhin1677 4 ปีที่แล้ว +2

    I like the fashion you bring the info, all videos could compliment each other like in this one, one could add report progress to coping files or etc that was learnt from previous videos, easy and helpful. Nice job!

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +1

      Great idea. Thanks for watching.

  • @sbmahapatra
    @sbmahapatra ปีที่แล้ว

    Hello Brian, thank you for the video. How can we do just the opposite? Meaning I have source folder which is not part of the project. The destination folder is part of the project. How to do it? Thank you!

  • @tusharparab9866
    @tusharparab9866 4 ปีที่แล้ว +2

    Hello Brian,
    Can we get a example of the drag and drop functionality in the WPF MVVM? Thanks in advance 🙂

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +1

      Thanks for the question. I'll what I can do

    • @99MrX99
      @99MrX99 4 ปีที่แล้ว

      GongSolutions WPF DragDrop library helps with that

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      Just to clarify, are you taking about drag drop of wpf elements within a WPF app, or dragging and dropping files from the file system into your wpf app?

    • @ievheniiierokhin1677
      @ievheniiierokhin1677 4 ปีที่แล้ว

      @@BrianLagunas i guess would be nice to see in action both:)

  • @johnmartin5986
    @johnmartin5986 2 ปีที่แล้ว

    How would you do this if the file location were set as a string in my code? Would it be the same only "string" instead of "var"

  • @munawarkhurshid1201
    @munawarkhurshid1201 4 ปีที่แล้ว +2

    How can I register HTTPClientFactory with Unity or DryIOC and then inject it via constructor injection in WPF Prism APP service?

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +1

      Great question. Thanks for asking

  • @chocolateandy1963
    @chocolateandy1963 4 ปีที่แล้ว +2

    Hi Brian. Another concise demo. As this is an I/O operation I was under the impression that Task.Run should only be used for a compute operation?

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +1

      That's a great point and something I did consider before taking this approach. However, there are no async APIs for using the File.Copy method. You would need to use Stream.CopyToAsync to implement something like that. I took the pragmatic approach. Even this approach could be improved by using the TaskCreationOptions.LongRunning option if the performance requirement needed it.

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      There's actually a good thread on this exact topic where this is being discussed github.com/dotnet/runtime/issues/20697

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      Here's another: github.com/dotnet/runtime/issues/20695

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      It seems that File.Copy is somewhat faster than trying to use Stream.CopyToAsync. So in this case, it looks like for now, using Task.Run for File.Copy is a good way to go. Hopefully a new async File.Copy API is coming soon 😁

    • @chocolateandy1963
      @chocolateandy1963 4 ปีที่แล้ว +1

      Thank you for that. Greatly appreciated. Great videos 👍

  • @hmixa
    @hmixa 2 ปีที่แล้ว

    There is a good question. Why this function does not exist in Framework yet? This is one from a basic operations.

  • @vladimirrylov5344
    @vladimirrylov5344 ปีที่แล้ว

    How can i create monitor progress? Windows uses DelayWrite so all of the c# .Net function that i know( except StreamFlush(true)) will return(or end) when the buffer loads to ram, and file might not be in physical drive physically yet. So for example without flush, File.CopyTo() and any other func will end, file will be created, but it will be it's ram representation, and windows will still be writing on disk for some time. (Maybe i just simply need another lng lol)

  • @bernisemg
    @bernisemg 2 ปีที่แล้ว

    do you have a video that does the same but with files in sftp?

  • @H4ckl
    @H4ckl 4 ปีที่แล้ว

    Hi Brian,
    I do not if this is right place to ask, but would like to see a proper demo how one should handle
    drawing and handling objects on WPF canvas with mouse in MVVM style. For example drawing a circle with mouse click, then dragging the circle with mouse
    (so that view model also updates holding the coordinates of the circle), and then having some neat way to also delete the the circle with mouse.
    Just a basic demo with concepts that one could build on to add more different shapes etc.and expand it further. Have been looking for a good examples from net and also
    found some, but there is always something missing or bunch of different concepts mixed together. Should one even think of using MVVM to build this kind of functionality?
    How about using behaviors and/or dependency properties to make this happen?

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      You would need two components to make this work. One would be an object model that represents the state you are trying to maintain in your VM. The other would be a UI control that can bind to your object model in your VM and represent that state / perform the required interactions. For example, Infragistics has a xamDiagarm component for WPF that allows data binding objects that represent drawings / diagrams www.infragistics.com/products/wpf/data-visualizations/diagramming

  • @VinuP2023
    @VinuP2023 4 ปีที่แล้ว

    Thanks Brian. I have a request for you. How do you handle exceptions in WPF. What are best practices to be followed. If you can do a video. It would help 😊

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      Hmm... try/catch/finally are the most common. Is there a specific scenario you are asking about?

    • @VinuP2023
      @VinuP2023 4 ปีที่แล้ว

      @@BrianLagunas how do we handle unhandled exceptions. Sometimes, user reports when they click on an UI control, application crashes. Instead of application crashing, what are some ways to avoid it?

  • @thompsonthong2053
    @thompsonthong2053 4 ปีที่แล้ว

    Hi, is it possible to copy the latest subdirectories and files with c#?

  • @SBDavin
    @SBDavin 4 ปีที่แล้ว

    Brian - could this have been optimized with a Parallel.ForEach()? What if the files were larger? No Sleep() necessary. ;)
    Thanks!

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +1

      Hmm. I'm not really sure what you would gain from that. Its possible that would gain something. If the files are really large, maybe using the Stream.CopyToAsync would be a better approach. Hard to say.

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว

      Thanks for the info Karl

  • @julianturner6203
    @julianturner6203 4 ปีที่แล้ว +1

    Hey Brain, thanks for answering my question. You are awesome! Highly appreciated 😊 can you tell me difference between EnumerateDirectories and
    GetDirectories? Thanks again brain

    • @BrianLagunas
      @BrianLagunas  4 ปีที่แล้ว +2

      The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.

    • @julianturner6203
      @julianturner6203 4 ปีที่แล้ว +1

      @@BrianLagunas finally that makes sense to me, you are the best.

  • @covid19master83
    @covid19master83 3 ปีที่แล้ว +1

    WOWW, Can you do this for VB.NET ? ? ? ?

    • @BrianLagunas
      @BrianLagunas  3 ปีที่แล้ว

      Sorry my friend, but I do not write VB.NET code. I'm mainly C#, JavaScript, and TypeScript

  • @valeryngwa
    @valeryngwa 4 ปีที่แล้ว +1

    Wow awesome.

  • @alexeypopov314
    @alexeypopov314 4 ปีที่แล้ว +1

    using Microsoft.VisualBasic.FileIO;
    FileSystem.CopyDirectory("copyFrom", "copyTo", true);

  • @adrien8768
    @adrien8768 4 ปีที่แล้ว +1

    😍