Working With The File System in C# - Managing Folders and Files

Поделиться
HTML-код
  • Опубликовано: 9 янв 2025

Комментарии • 385

  • @RalfsBalodis
    @RalfsBalodis 4 года назад +10

    0:42 - creating a demo console application
    3:15 - reading all directories in the path specified
    7:29 - reading all files in the path specified (directories included)
    9:43 - reading all files (directories excluded), omitting file extensions, getting file path only
    12:09 - information about the file
    15:10 - automation with c# - manipulating file systems and files.
    16:21 - verify if directory exists
    18:42 - creating a new directory
    21:34 - copying files
    28:28 - moving files
    29:40 - utilize - create your own utility apps

    • @sakibahammed7909
      @sakibahammed7909 4 года назад +1

      Thank you so much for listing the info

    • @RalfsBalodis
      @RalfsBalodis 4 года назад

      @@sakibahammed7909 sure ;)

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      Thanks! I updated the description.

  • @Sea-qv4sd
    @Sea-qv4sd 3 года назад +1

    Although a number of your videos are for more serious learners and professionals, tutorials like these are amazing. Helps a great deal and I do not have to read through google

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 года назад

      Tim strives to produce training for multiple levels of students. We are glad this one worked well for you!

  • @tsheposepadile
    @tsheposepadile 3 года назад +4

    You really are making learning C# easy. Thank you.

  • @urbzNspicez
    @urbzNspicez 4 года назад +1

    Great video, and great suggestion at the end!!
    I have been watching and coding along to a bunch of your videos, and after I saw this one I decided to code a project that would move all the practice projects into their own folder. I have a naming convention (every Tim Corey video-project I make starts with "TC") so I wrote a tiny class library to search for and fetch those solution folders from my repos folder, and move them to a different folder. I use one call to one method in a console app and boom! all my TC solution folders are moved, no messy cut & paste with folders. Had a great time doing it too!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      Glad to hear it. Great example of the benefits of following consistent naming conventions.

  • @m7clarke
    @m7clarke 5 лет назад +1

    Hi Tim, great tutorial on the file system basics.
    At around 23:45 you mention using string interpolation to combine destination folder, slash character and file name. I find using _Path.Combine_ is helpful as it takes care of adding the slash character if necessary, e.g.
    string destinationFileName = Path.Combine(rootPath, "SubFolderA", Path.GetFileName(file));

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      Thanks for the tip!

    • @PinkyParu
      @PinkyParu 4 года назад

      I was also thinking the same, which one could be better, Path.Combine or $ syntax. :p

  • @karendoran3692
    @karendoran3692 6 лет назад

    Tim, this is awesome! This is perfect for some file maintenance issues that I sometimes have to periodically perform. I used to do a lot of this manually years ago and then wrote routines using VBA that does it pretty well but now I will write this in C# because who wants to use VBA anymore!

  • @dianew274
    @dianew274 5 лет назад +1

    Seriously some of the best videos to help learning on the net

  • @orientgamessa1340
    @orientgamessa1340 4 года назад +2

    Thank you so much for this Tim! This was a phenomenal video, so well explained and its helped me tremendously! You're the best!

  • @cecilchampenois4998
    @cecilchampenois4998 11 месяцев назад

    Tim Corey does a great job of explaining these and other concepts.

  • @thedude4039
    @thedude4039 4 года назад

    Halfway through and I already made a program to make backups of files. This is a great video!

  • @i-know-alice3874
    @i-know-alice3874 5 лет назад +3

    Mate you are my hero. Definitely subbing

  • @showmeyourdata2649
    @showmeyourdata2649 Год назад

    Im just looking for something else in C#, found this, watch and .... very good material, clearly and very interesting. Easy to understand and ver helpfull with the studies level. Very good job and profesional job mate. Keep going. !

  • @MHellman
    @MHellman 5 лет назад +1

    Just what I needed. Excellent! I'm gonna use this to make backups of my Garmin GPS units. Thank you!

  • @lootcrate3800
    @lootcrate3800 Год назад

    Really good complimentatory video to let myself expand later on this subject. I can see this being very important creating a database perhaps? or maybe for when you work with software that needs to be installed in certain directories. In any case, love your clear explanations. It has helped me understanding the more practical side of programming whenever my teacher has chose to go the more..specific and complicated route [Which is obviously neccessary too, but difficult for me to digest. Which is were your videos really shine for me].

  • @mikey803
    @mikey803 5 лет назад +1

    Good video, sir. I have been using only the tip of the file services with projects at work. I had an "aha!" moment. I have been getting the file names, the long way, by searching for the last slash, and removing everything up to the last slash. I am looking forward to using these newly acquired things for my application.

  • @ZeroSleap
    @ZeroSleap 4 года назад

    12:59 You scroll on the info you can get off the file,and below length theres Name,you shoild generally reuse the info instance for both those things instead of calling a new Path.GetFileName which probably is more taxing

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Thanks for the tip. That comes down to what one is used to doing.

    • @ZeroSleap
      @ZeroSleap 4 года назад +1

      @@IAmTimCorey Another thing to add to that is you can instead of calling Directory.GetFiles which returns a string[]
      call DirectoryInfo.GetFiles() to return a FileInfo[] where each of that contains the name,extension,length,etc

  • @brkkrks
    @brkkrks 6 лет назад

    Tim, you make my life easier. Thank you so much.

  • @MrLuckyalmond
    @MrLuckyalmond 4 года назад

    Awesome video as always. Thank you, Tim!

  • @jpalleau
    @jpalleau 6 лет назад

    Hi Tim,
    As usual excellent and very clear !!!
    Thank you so much !!!!!!!!!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You are most welcome. Thanks for watching.

  • @abdallaelmedani8933
    @abdallaelmedani8933 2 года назад

    Thank you so much for this tutorial Corey. Super helpful!

  • @isaahliu
    @isaahliu 6 лет назад +6

    First thing: upvote.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Thank you!

    • @toriishinto3074
      @toriishinto3074 2 года назад

      @@IAmTimCorey
      Hey can you help me with something? I need to graduate and I have a project, can you help me resolve some of the issues I face? I know this sounds super absurd, but I'm really desperate.

  • @njugunapatrick2546
    @njugunapatrick2546 3 года назад +2

    very clear and useful content

  • @taraspelenio8259
    @taraspelenio8259 4 года назад +1

    Good English, pronunciation as a native speaker(I believe you are). Nice to learn C# with your videos.

  • @davidramirez3322
    @davidramirez3322 6 лет назад +1

    a New World !!! , thks so much Tim!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You are most welcome. Thanks for watching.

  • @demariners
    @demariners Год назад +2

    Do you have an in depth video explaining how to use Streamreader and Streamwriter instead of these methods? Not sure they are better in anyway regardless. Thanks for what you do!

  • @uwejadick4550
    @uwejadick4550 3 года назад

    Thanks Tim. I just watched the video about storing images in the database and then I found this one. Now I have a much better solution than I was planning. Your videos are helping me a lot designing my application and learning C#.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      Awesome!

    • @uwejadick4550
      @uwejadick4550 3 года назад

      @@IAmTimCorey So are your videos. You should see what you achieved with your tutorials. I have never created an entire application before. It really shows how good your tutorials are.

  • @muadzafandi6764
    @muadzafandi6764 2 года назад +1

    Hi @iamTimCorey for 7:29 , I would like to know can we read certain paths and not read all the paths that you explained in the video

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +1

      I’m not sure what you mean?

  • @malachyokwute3010
    @malachyokwute3010 10 месяцев назад +1

    Really good detailed explanation. Could you demonstrate how to get files or directories on a drive using MFT ?

    • @IAmTimCorey
      @IAmTimCorey  9 месяцев назад +1

      Thanks for the suggestion. You can post it on suggestions.iamtimcorey.com so that others can upvote it.

  • @Fibr3Optix
    @Fibr3Optix 4 года назад +1

    What a wonderful clearly explained video.

  • @sphxcyprex1923
    @sphxcyprex1923 5 лет назад

    Good video, high-quality content! Love it!

  • @fadidib8516
    @fadidib8516 2 года назад

    Thx for the video, very instructional for people learning files.

  • @AHMED-dl5hn
    @AHMED-dl5hn 2 года назад

    I really appreciate your tutorial, you helped me alot in my project❤

  • @zoetrender7386
    @zoetrender7386 4 года назад

    Thanks for this and all other great videos! I would really appreciate a video on some best practices regarding file encoding and different character sets which I find tricky.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      I will add it to the list. Thanks for the suggestion.

    • @keithdeslippe4457
      @keithdeslippe4457 4 года назад

      Hi, if your interested, Scott Hanselman has a few good video's on this.
      ruclips.net/video/TtiBhktB4Qg/видео.html
      and
      ruclips.net/video/jeIBNn5Y5fI/видео.html
      I know, kind of seed-ie to post this here, but i only watched these vid's a week ago and it is some good stuff.

  • @reidondiesnatz8131
    @reidondiesnatz8131 3 года назад +1

    Could you maybe tell me the shortcut you used at 4:12 in order to complete the for syntax? Would be a lot of help!

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +2

      I used the "foreach" snippet. When you type foreach and tab twice, it fills out the shell of a foreach loop. You can do the same with "cw" (Console.WriteLine()), if, else, and many more.

    • @reidondiesnatz8131
      @reidondiesnatz8131 3 года назад

      @@IAmTimCorey Thank You

  • @anuraggupta7969
    @anuraggupta7969 3 года назад +1

    Awesome video. You rock sir. Thanks a lot and god bless.

  • @mmuneebajaz
    @mmuneebajaz 6 лет назад +4

    Suggestion : complete series of mvc can be helpfull :)

    • @jimlynch8313
      @jimlynch8313 6 лет назад +1

      He does have a complete application from start to finish for MVC, if that's something that you'd be interested in. It's a good "next step" from his MVC tutorials.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +3

      Yep, my C# Application from Start to Finish has an add-on course to make a MVC user interface. The business logic and data access are both done in the original project so the add-on just concentrates on the user interface.

  • @TheArose4u
    @TheArose4u 6 лет назад +1

    Thanks again for the great video.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You are most welcome. Thanks for watching.

  • @ademineshat
    @ademineshat 5 лет назад +1

    I've used this Windows Application for the Users Files, the path was stored in the database for every user.
    Days long I couldn't figure out how to put those files in the ImageList so they can look pretty same as windows explorer :)

  • @Allyourneedsmet
    @Allyourneedsmet 2 года назад +2

    Hello Tim, how about accessing files in your project or solution directory.
    Is there a better or less complex way, instead of adding it to the assembly?
    Directory.getcurrentDirectory() returns absolute path/bin/debug/5.0 when clicking the play button but with dot net run, it returns absolute path of which I can then run Path.Combine.
    Please, how can I access a json or text file in my data folder?

  • @sehamhammad8549
    @sehamhammad8549 4 года назад

    Hi Tim,
    Thanks very much for the great video, I am wondering how would u deal when u try to move few files where one of them such as word doc is opened, how will make the program working for the rest of files in the folder. I have tried try and catch, but the only file that it can see in the folder is the opened file and not the others.
    Thanks for your help in advance

  • @oz7075
    @oz7075 5 лет назад

    Gotta love your videos, Tim. So far, each and every one of them has been amazingly useful. I like the pace and the fact that you know your thing by explaining why things are the way they are. I'm still in the learning process after two months of hard work because I love programmig. Though I'm a Mechanical Engineer, I've got my mind set on the idea of becoming a software engineer (back-end or something in between related to mechanical engineering, like IoT). I've made it until delegates, reflection and LINQ. Any recommendation on what to do next? I've already started a MySQL course and I'm finishing a desktop application that connects Autocad (a 2D design program), Excel (the pricing is downloaded into a PowerPivot table connected to SQL, basic queries, no rocket science) and a final quotation (displaying images and the corresponding wording whenever possible, you know, just for standardized solutions). You know, learning by practising. If you have any ideas on what steps to take next, I'll be more than happy to read them, if not, thanks for these great vids. Keep it up!

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      The following page has a PDF on it that outlines a learning path for C#. You can figure out where you are already at on the path and go forward from there: www.iamtimcorey.com/p/learncsharp

    • @oz7075
      @oz7075 5 лет назад

      @@IAmTimCorey Thanks a lot, Tim!

  • @drip888
    @drip888 3 года назад +1

    when i try to copy the file .csproj (this is a file created by visual studio when we create a new project)
    it doesn't copy the name, rest all files are fine except this. the file name that comes up is like there is no name. so i tried using console.writeline() to see the filename while its copying stuff and the thing is, in the console.writeline(), its showing the file name as .suo
    the extension of the file is not even .suo and it doesn't show the file name. please tell me why this is happening.
    if i use CTRL+C and V for copy paste, it paste properly with the proper way .csproj

  • @jasper5016
    @jasper5016 5 лет назад +1

    Great tutorial. How about creating and writing information to the file?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      Here you go: ruclips.net/video/cST5TT3OFyg/видео.html

  • @GabrielsEpicLifeofGoals
    @GabrielsEpicLifeofGoals 3 года назад +1

    What if I have a compiled C# file inside of a directory, and I want to look at a file outside of that directory, without typing the whole path from the C:? I need that for my project to work...

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      If you use two dots at the beginning of a relative path, it goes up one level (like “..\test.txt”). You can do that multiple times to go up multiple levels.

  • @hungnguyencanh5013
    @hungnguyencanh5013 4 года назад

    Thank you, Tim, awesome!

  • @ManiasInc
    @ManiasInc 2 года назад

    thanks for the video and the clear information!!! 👏👏😃👍

  • @ZeroSleap
    @ZeroSleap 4 года назад

    I have always had the question of,how would i setup a file manifest for an app.
    What i mean by file manifest,is a file that contains the directories of all required files from the application.I've tried doing it and i've had success but i felt it was a naive and sloppy implementation of what i thought was correct.
    I don't have a notion of how would one would approach handling all the metadata for the required files of an app.

  • @shadowking8223
    @shadowking8223 5 лет назад +1

    Do you happen to have resources on file hashing and comparing it like in a hash table for C#?

  • @sbmahapatra
    @sbmahapatra Год назад

    Hello Tim, Thank you for the nice video. Is there a way we can do the same things in the project Directories? For example, I would like to copy a file to Image folder. It should be included in the project.

  • @gauravparvat5291
    @gauravparvat5291 6 лет назад +1

    Just one complaint. Green font on black console is reeeaallllyyyy hard to see. Especially the first line at the top. Either bump up the font or change the font color to white or any color that has great contrast with black.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Interesting. I see it as a much better contrast than white. I wonder if it is because green is so easily seen differently or something else. I'll play around with the colors and see what I can do.

  • @raydleemsc
    @raydleemsc 2 года назад

    I can't find out what key sequence he does at 10:29 to get the list of alternative methods

  • @abdelkiki
    @abdelkiki 3 года назад +1

    Thank you for this video

  • @MrBan001
    @MrBan001 4 года назад

    What are best practices about Paths... How do i store paths? a static class? For example when i want a temp folder inside my bin folder where do is store the path to this folder

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      Usually you would store it in the app.config (or appsettings.json if you are using .NET Core) since you could change it at runtime. However, there are times when a hardcoded relative path is the right choice (settings, a cache, etc.)

  • @MrNutmegdesigns
    @MrNutmegdesigns 5 лет назад +1

    There seems to be a limit to how many files and/ or sub directories run through. I can get this to work fine with TopDirectoryOnly but I do not get any results with AllDirectories on a subdirectory which has 50 folders and 4K files.....

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      You would want to make the call async and maybe break it up as well to read that many. The limitation is actually your computer's setup. You can do a top-level call, find the directories inside it, do a top-level on each sub-directory, etc. until you traverse the whole set. Async will also help.

  • @n9434178
    @n9434178 6 лет назад

    Thanks Tim. One Question - why work with strings (e.g. Directory.GetFiles) if you can have an array with FileInfo objects? var dir = new DirectoryInfo(E:\yourtestdir); FileInfo[] files = dir.GetFiles(); Is one approach better than the other or is it only a matter of taste and perhaps use of system resources?

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Good question. It is a matter of resources. If what you are looking for is just the file or folder names, the way I showed is much more efficient. Typically I find that is the most common usage. Then, if you want the info on one file, you can get it.

  • @rafliiskandarkavarera2886
    @rafliiskandarkavarera2886 5 лет назад +2

    Nice tutorial, how to get file name in c folder like documents and setting, it said access denied. How to get the permission? Do you have the tutorial?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      The application runs under your permissions (the person who launched the application), except under rare circumstances. My guess is that you were trying to read the folder of other users on the PC. If you want to have access to those folders, you will need to elevate the permissions of the application. If you are running the EXE, run it as administrator. If you are launching it from Visual Studio, run Visual Studio as administrator.

    • @rafliiskandarkavarera2886
      @rafliiskandarkavarera2886 5 лет назад

      @@IAmTimCorey i've run visual as administrator but it doesnt work. And i change the mainfest to level 2(i forget the name. Its between asinvoker and highestpermission.) Then run the exe as administrator and its doesnt work too.

    • @james47817
      @james47817 5 лет назад

      @@rafliiskandarkavarera2886 Are you getting an un-handled exception that breaks your console app?

    • @rafliiskandarkavarera2886
      @rafliiskandarkavarera2886 5 лет назад

      @@james47817 yes

    • @james47817
      @james47817 5 лет назад

      @@rafliiskandarkavarera2886 A try/catch should solve your problem if you just want a user friendly error message, but unfortunately I don't know how to get the permission either.

  • @mauriciokenny2674
    @mauriciokenny2674 2 года назад

    Thank you Tim !!

  • @PinkyParu
    @PinkyParu 6 лет назад

    Long back when working with files, I had a long path that system was not accepting it. But the same time i have noted window was handling those paths with ~ symbol for making the path short. How it is possible in program

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      That gets tricky. The best way is to use relative paths (paths starting from where you are at so ".\Temp" goes to the temp folder inside your current folder where your exe is running). There are some places in C# where you can use the same tilde pathing but other places don't like it.

  • @vanshikagupta1758
    @vanshikagupta1758 3 года назад +1

    Hello,
    I want to run sig check into my shared folder to check for unversioned files through c sharp code...How I suppose to do that?

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      I'm not sure what you are asking for.

    • @vanshikagupta1758
      @vanshikagupta1758 3 года назад

      @@IAmTimCorey i create console application and I have shared folders with my frnds.. I need to run a task scheduler which check in that shared folder for corrupt files.. For this, i am using sigcheck..
      How i suppose to run sigcheck on my shared folder in c sharp?

  • @emaus8344
    @emaus8344 5 лет назад

    Thanks for the video! Is there any chance that we can know what document was last modified in Directory, and based on that open that file for writing?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      Yes, there is a way to monitor the directory for changes to it and trigger an event based upon those changes.

  • @AAA-f3z1p
    @AAA-f3z1p 4 года назад

    Thanks for excellent video, what about if I need to add multiple extension (specific extension) how?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      I do not understand the question.

    • @AAA-f3z1p
      @AAA-f3z1p 4 года назад +1

      @@IAmTimCorey sorry , i mean the code line : Directory.GetFiles(rootPath, "*.xlsx");
      So if I need add more extension to code like : *.pdf
      So I can just copy the file has extension (xlsx) and (pdf)
      Thanks for your time

  • @ndudimokezie5421
    @ndudimokezie5421 2 года назад

    This is really helpful. So what if one wants to change file type or extension type?

  • @rasikakavankar5239
    @rasikakavankar5239 2 года назад

    Hi Tim,
    I am working on web aplication c# hosted on azure.
    Basically I working on virtual machine. (Ctrix)
    I have file data in format of byte[] array in side code and want to save/download it on local, but i am not able to do that.
    For download I used response streams
    Example :- Response.output (data) / Response.Binarywrite(data).
    *This Didn't work*
    Or
    To save on local I used desktop path string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    Above code return some different location wich is not accessible for me.
    Error : D:/Windows/System32 not accessible.
    Whenever I used above code for access desktop it always work without any error.
    But looks like as I am working on virtual machine and aplication is also hosted on azure that's why it's returning some different path.
    Please help me how I can save/download file on my local.

  • @ishan9050
    @ishan9050 2 года назад

    Is there a way to access the file details of a multimedia file via C# only? Or by any other means? Like the length, bitrate, resolution (in case of a video file). I really need this.
    Thanks

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      I don't have an example for you, but you will need to real the file properties. That will probably involve some operating system tie-in or you will need a third-party tool to evaluate the file directly.

  • @petermwansa5049
    @petermwansa5049 4 года назад

    Thank you so much bro big ups this has really widened my understanding of files
    but I've got a question, how can i search for files having the same size?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      List all of the files and sort the list by size. Or look through the files and only save the paths of the files that match your size criteria.

  • @mrwhammer
    @mrwhammer 2 года назад

    So I am having trouble with emailing attachments. I have all of the smtp set up and its not generating the form to attach the attachments. Im just trying to get the attachments from a specific directory.
    List attachments1 = new List();
    attachments1.Add(@"C:\Users -report.xlsx");. I understand this attaches the file but Im not sure how to get it to send along with the body and subject and from and everything else. The email works completely fine

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      You aren't actually attaching the file here. You are just adding the file path to a list. You need to talk to your mail object and add these files as attachments.

  • @mncedindovela1227
    @mncedindovela1227 5 лет назад +1

    Morning,
    Thank you for a lecture, this code seems clear and easy until I tried to use it in my project. The problem I faced is I want to display it in a Textbox or Listbox but now "Path" refuses all the visual studio recommending references and it stays an error.
    Can anyone please assist? I do not want to use Console to display as in this project above.
    Thank you,
    Mncedi

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      Path is located in System.IO; You shouldn't need a reference to access it. It should work in most project types. It even works in Blazor. My recommendation is to follow along with what I did in the video and get that to work before you try to do it in a different project.

    • @laggybot1327
      @laggybot1327 4 года назад

      @@IAmTimCorey bro help me also

  • @emaus8344
    @emaus8344 3 года назад

    Hi! Why do I get an Exception when trying to create folder, even though I have full access? - unauthorised access exception.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +1

      You may have access but your app may not. Check what permissions your app is running under and if it needs to be elevated in order to access the folder.

  • @eamchet2680
    @eamchet2680 4 года назад

    Hi sir
    Can you help me show audit who create, Delete and Move file or folder using c#?

  • @cyberthunder1012
    @cyberthunder1012 3 года назад +1

    great video and its help me for make a my antivirus software

  • @divyagautam3185
    @divyagautam3185 3 года назад

    Hello,
    I wish to set a cloud folder (BOX) as my input folder. Whats the way for it? What nuget packages should I have installed? TIA. :)

  • @jasperchia250
    @jasperchia250 2 года назад

    Would you happen to know how to detect when files are being closed? Sometimes we want to move or manipulate files but the file is currently in use. How do we handle that and when the file is closed how to we tell the programme that it is no longer in use?

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      You would need to tie into the file system directly for that, I believe.

    • @jasperchia250
      @jasperchia250 2 года назад

      @@IAmTimCorey Hi Tim Corey, thanks for the reply. Any details on how I could do this exactly? Perhaps you could link me up with another video or weblink

  • @themagecan
    @themagecan 5 лет назад +1

    Wonderful!!!👍🤓

  • @DanielPizarro184
    @DanielPizarro184 5 лет назад

    Hello, is there anyway i could display the directories in the following way:
    1. Directory
    2. Directory2
    3. Directory3
    Thank you.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      Once you read the directories into C#, you can display them in any order you want.

    • @navjotsingh2251
      @navjotsingh2251 5 лет назад

      Use a for loop

  • @JeloOW
    @JeloOW 4 года назад

    Hey, how would you do it for Documents folder tho? Since other users have a different user name than mine

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      You can use a relative path or you can use the special folder path like: %UserProfile%\Documents

  • @alannamuldoon9673
    @alannamuldoon9673 2 года назад +2

    what if you do not want to hardcode the file path is there an alternative?

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      You can put it in the app.config (if you are on .NET Framework) or appsettings.json (if you are on .NET). You can also use a relative path.

    • @phat80
      @phat80 Год назад

      Or use args of command line when you launch your app.

  • @Sam-su4sk
    @Sam-su4sk 4 года назад

    Hi, Awesome video thanks. How would you go about checking if a file is already open in a stream? Thanks!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      In a stream? If you have opened a file in a stream, it is open. If you mean to check if the file has been opened by someone else in a stream, not sure if that is specifically possible.

    • @Sam-su4sk
      @Sam-su4sk 4 года назад

      @@IAmTimCorey Thanks Tim

    • @mlibby05
      @mlibby05 4 года назад

      You could attempt to open the file with a FileInfo.Open and then capture the System.IO.IOException that is thrown when the file is in use.

  • @marandreslopez1263
    @marandreslopez1263 2 года назад

    Hi! A lot of thanks for this video, Do you have a video in which you explain how to Zip a large amount of files in an efficient way? Or best practices for dealing with copying a large amount of files and make It as fast as posible? Would like to watch It.

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      I don't have it yet, but please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @rahulhadgal
    @rahulhadgal 6 лет назад

    Create videos that end up with an awesome piece of usable tools. That way you will teach basics and think process. For eg: create a CSS minifier or SQL Server database backup, zip and storage, etc., This will spike up your subscribers list and views. This creates interest in viewers and the result is an useful tool they can use. It's my suggestion.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      Those are great ideas but they are REALLY difficult to do, especially in one video. A video series is great but it actually reduces viewership. People see that it is video 4 in a series and they don't bother starting from the beginning or they start in the series but lose interest. Some projects can be done (and I'll be doing a few) but mostly they are too large to tackle. I've been wrestling with just this thought though. What topics can I do in 60 minutes or less that would produce something helpful? I'd love to hear your thoughts. The SQL backup would be one. Not sure about the CSS minifier, especially since that is built into Visual Studio.

    • @rahulhadgal
      @rahulhadgal 6 лет назад

      IAmTimCorey You are right about multi videos of single project. Small things even if they exists done thoughtfully will help people learn C# with thought process. You can create a video on file watcher to merge multiple files or single file parse into something else like a new HTML kind of language, etc.,

  • @simon-white
    @simon-white 4 года назад

    Hi Tim, something like a file management app watching a folder seems like it would either have to run all of the time (and be low on resource usage) or be executed at regular intervals. On Windows at least, this sounds like something for either the program start-up list or Windows Scheduler respectively, but I'm not sure if these are the best options. Have you covered anything like this in your videos?
    Thanks again for another excellent session. Wish I'd seen this before I made custom methods to extract filenames!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      There are events you can listen to for file changes so they are able to be run all of the time in a service.

  • @gazzolapw
    @gazzolapw 3 года назад

    Hi Tim Is there any vidio of yours about writing and reading info from a .txt file? (C#)
    Ty

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 года назад +1

      ruclips.net/user/IAmTimCoreysearch?query=text - this should address your question. Check out all Tim's videos here - ruclips.net/channel/UC-ptWR16ITQyYOglXyQmpzw. Use the "hidden" search tool under the Subscribe button to find specific topics you may be interested in within the channel. With over 100 videos on C# and related topics/tools, Tim will likely have what you are looking for.

    • @gazzolapw
      @gazzolapw 3 года назад

      @@tomthelestaff-iamtimcorey7597 I will watch it now. Thank so much :D

  • @InsidiousRat
    @InsidiousRat 6 лет назад

    Hello. I am afraid I didn't understand some of those manipulations with search patterns. I understand, that "*s" means that we will find all files that end with "s". "t*" means that we will find all files that start with "t". And what does "*.*" mean? That we will find all files that have "." somewhere in the middle of their names?

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +2

      Sorry, I grew up with the command line (DOS mostly) so these commands are ingrained in me and I forgot to explain. You are correct in your assumptions about the * character. It represents a wildcard of 0 or more characters. So "s*" would match "s", "sam", and "sandwich" but not "mask" because "s*" means it starts with "s" and then has 0 or more characters after that. The last one has an "s" but does not start with one. "*.*" indicates that a name has 0 or more characters, then a dot, then 0 or more characters. This indicates that an item is a file (files should all have extensions, folders cannot have a dot in the name).

  • @jeffeastman9878
    @jeffeastman9878 3 года назад

    Hey @IamTimCorey (or anyone watching this video), does anyone know if Tim has a video that covers the actual deployment of a small app like this to a Windows server? I want to write a small program like this that will basically always monitor a directory on a server, and when a file gets placed there it will automatically be picked up for processing. I'm not sure if I need to run is as a service, or what the best deployment option is to ensure the app is always running/monitoring a folder.
    I'm just looking for some very basic/bare bones instructions on how to deploy a small app like the one in the video to a Windows server. Thanks!

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +1

      It sounds like you want a service, which this video will show you how to create: ruclips.net/video/PzrTiz_NRKA/видео.html

    • @jeffeastman9878
      @jeffeastman9878 3 года назад

      @@IAmTimCorey This is exactly what I wanted, thank you TIm! Your videos are amazingly helpful.

  • @henrik3098
    @henrik3098 2 года назад +1

    thanks man appreciate it

  • @lakkidikarthik8560
    @lakkidikarthik8560 2 года назад

    Hi, i need some help related this in my work. In a folder on daily bases some new files are adding by job scheduling. I need to scan only the newly upladed files from that folder. But in my case it is getting scanning all the existing files also even it is not uploading in database but scanning all the files.

    • @lakkidikarthik8560
      @lakkidikarthik8560 2 года назад

      Daily it will uploaded 100 new files. By scanning all the folder there are n number of existing files and at that point of time if there is a connection/server error. Files are not uploaded in database lot of headache

    • @lakkidikarthik8560
      @lakkidikarthik8560 2 года назад

      I just needed to scan only newly uploaded files in the folder. I hope u got it and u will help me with this. Thanks in advance

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      Sounds like you have some logic to write and some debugging to do. For the logic, store the list of files you have already processed and their last update date. Then, when you get a new list, loop through and ignore anything that hasn't changed based upon your existing list. Then process the new/updated ones and add them to the list.

  • @joshibhushan1
    @joshibhushan1 2 года назад +1

    I usually struggle with getting relatives paths of projects and environment variables handling in AppConfig files.I always get confused \ or\\ or ..\\..\\

  • @DD-ed9rd
    @DD-ed9rd 4 года назад

    Hi, I am doing my Final Year Project. I am stuck at a lot of parts. It will really be appreciated if u can help. I am creating an app using c# where when u order u get 2 options of drinks (Pepsi or Cola)... After finishing your order, the data are being stored on text file (order.txt). My question how do you add in status like real life time,date, status(complete,Initiating) on the microsoft sql server?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      I am not sure what you are asking. Are you asking how to write the time and date, among other things, to a text file? I have a video on that here on RUclips: ruclips.net/video/cST5TT3OFyg/видео.html If you are asking how to do it in SQL, mostly it is just sending the data you want to SQL to be written.

  • @AntonioZanotto
    @AntonioZanotto 3 года назад

    Great video.

  • @TFitz
    @TFitz 6 лет назад

    Great information! How could one make this code testable, or is it and I am missing something?

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You would need to mock the calls in System.IO and then you could test them. If that causes you issue, create a really thin class that just wraps the calls and then mock that class instead but you shouldn't have too much trouble mocking the System.IO class.

    • @TFitz
      @TFitz 6 лет назад +1

      @@IAmTimCorey Thank you very much. I very much appreciate the time you have spent putting these videos together. So much I should have known for years and am finally learning. You have been a tremendous asset!

  • @i.eduard4098
    @i.eduard4098 Год назад

    Got an interview task where I have to keep in sync two folders, one should be a replica of the other.
    It doesn't seem hard... but I was wondering how can I do this real time. Like you go in the window folder delete something and my program would pick that up.
    The role is for a junior... I am thinking to do a periodical check with a Timer on the original folder and just compare the files and their sizes.
    What do you think corey?

    • @IAmTimCorey
      @IAmTimCorey  Год назад

      That would work, although it is probably easier and faster if you tie into the Windows events to monitor the folders for changes.

    • @maniaco123321
      @maniaco123321 Год назад

      You did it?

    • @i.eduard4098
      @i.eduard4098 Год назад

      @@maniaco123321 i failed that interview, got in a better company tho

  • @landon.cunningham
    @landon.cunningham 4 года назад

    What's the best way to turn a file path into a UNC path - so that file can be accessed no matter where it was saved from as long as it's on the same network?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      You have to allow access to your drive or folder by sharing it to the network. Then you can navigate through that path to get to your file. It isn't about just changing the link path, it is about sharing the drive or folder first. That will determine the start of the UNC path.

    • @landon.cunningham
      @landon.cunningham 4 года назад

      @@IAmTimCorey what I am talking about can be done without setting up any sharing. If I am at computer A and I set a software file location for part imports to c:\imports I can't save that path if computer B starts up and uses that same profile setting. It must be saved as \\Computer A\C$\Imports. I don't care what sharing is or isn't setup - at the time the save takes place that is what I need. This is more challenging than you think because one approach you come up with might not work for all situations. I've looked all over the place online - and C# has no built in functionality that will tell you what UNC path a file location is - or what UNC path a mapped network drive is. As you can imagine at mapped drive presents another problem because that locations isn't the same machine name.
      I did come up with my own solution - I may do a video of it myself since I can find nothing anywhere online for it.

    • @Feedback406
      @Feedback406 4 года назад

      Please make a video thank you!!

  • @Eloise__zara
    @Eloise__zara 3 года назад

    If we find the latest file how to send the output through outlook in c# , can you explain that

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      I don't have a demo like that, sorry.

  • @cobintern7865
    @cobintern7865 5 лет назад +1

    Can we also get folder names as we do file names?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      You can. Use the Directory class instead of the File class.

  • @barakkadosh
    @barakkadosh 4 года назад

    hii good video
    i have 2 folders
    1 source and every day i have in this folder some new files
    i want to copy just the new files from the source
    how can i do it ?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      You would need to load all of the source folder files in, look at them all, identify the new ones (probably by date updated), then copy the newer ones to the destination.

  • @no7060
    @no7060 5 лет назад

    Hi
    Can you please explain how to get the last saved user of excel/CSV and text files using c #

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      I don't have a video on that but if you look at the File options, you might find what you are looking for.

    • @no7060
      @no7060 5 лет назад

      @@IAmTimCorey the issue is not able to get the file last saved user. I am able to get the file last modified time but not finding any options for the last modified user

  • @RalfsBalodis
    @RalfsBalodis 4 года назад

    I guess one does not simply access portable devices that don't have drive letter.
    I wanted to practice this topic in the video and write a little console app that would manipulate files in my smartphones (android) directories.
    Lets say copy all pictures form my phone directory to somewhere on my PC's hard drive. Delete duplicates or not to copy files I already have on my PC's hard drive or whatever.
    The point is that
    "This PC/Samsung Galaxy S7\Phone\DCIM\Camera"" is not a valid path because of "This PC/".
    It didn't occur to me, that I wouldn't be able to do this.
    What am I treading on here?
    Can you point me in the right direction?
    Thanks.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      My guess is that the file name doesn't start with This PC if you actually look at it. Put your cursor in the Windows Explorer path bar and you should see the actual path. Copy that and try it.

    • @RalfsBalodis
      @RalfsBalodis 4 года назад

      ​@@IAmTimCorey Hello Tim. I don't know if you might be interested to further discuss this. However someone else might find himself in same situation.
      As for your guess:
      This is not so simple. This is exactly the path, that Windows Explorer shows and where I got it form in the first place. I should have made it clear. My bad. So there are other things I tried:
      I opened file properties for the file in my phone. It says "This PC/...";
      I created a shortcut on my desktop. The path also says "This PC/", however it is actually a copy of the file, stored in C:\Users\{User}\AppData\Local\Microsoft\Windows\INetCache\IE\QIT2QUKU;
      I tried to bring in existing item in to my c# project. The file is stored on my smart phone. Just to try to find out the path VS wants form me. Visual Studio threw me an exception:'basePath' cannot be an empty string ("") or start with the null character. Parameter name: basePath
      I also looked for info online. I guess one would have to modify ones Visual Studio installation and add "Universal Windows Platform development" and some optional "Windows 10 SDK" packages. This has something to do with Media Transport Protocol (MTP) devices and Mass Storage Class (MSC) devices. I'm not sure. I'm just starting out :)
      I'd love to see a video from you discussing how one may talk to or control other devices using C# applications.

  • @baraahamoood3372
    @baraahamoood3372 2 года назад

    I am trying to save an image or pdf to a directory which i got from a form file can you make a video on that

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      I'm planning on covering that in this video if people are interested enough: suggestions.iamtimcorey.com/Details/6253bf2a0b6906f2d6876be7
      Feel free to add your vote to the list.

  • @dorperetz-videofilmingedit6561
    @dorperetz-videofilmingedit6561 5 лет назад

    Hey, thank you for the video, can you help me and give me some dirction on how to open my program from a file in my desktop and then let the program read whats in the file?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      I don't have a video on that yet, but I'll add it to the suggestion list.

    • @tomservo75
      @tomservo75 5 лет назад

      Yes I would like to second that suggestion, I was just about to make that same request! What I'm looking to do is to make a small picture viewing app. I want to have two Windows forms. On the first I'd have the usual Windows directory dropdown box. Select a folder and populate a listbox with the relevant files. Then I want to make an array of those file locations, have the program select a random number to "randomly select" one of the pictures and display it in the Picture box on the other form. The other form should be resizeable too.
      I don't expect a video on this exact thing of course, but just to give the general idea: How to open directories on a Windows form app, store file names in a listbox/array, etc.

  • @TheBausahab
    @TheBausahab 4 года назад +1

    thank you very much Sir;

  • @redgamestream
    @redgamestream 3 года назад

    Great video! But one question, when I click to download source code files it says "This item might have been deleted, expired, or you might not have permission to view it. Contact the owner of this item for more information." so did you remove the files or it is just a bug or something else. I would really appreciate if you upload files again.

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 года назад

      Thanks for the heads up. Please send me an email at Help@iamtimcorey.com with your contact info and the blog post link. I will get you the info and get that link fixed as well.