How to find folders and files by its partial name c#

in a specific folder of my hard drive i have stored many other sub folder and files. now i want to list those folders and files name by their partial name.
for example
c webapi xx folder
c mvctutorial xx folder
done webapi xx folder
webapi done folder
webapi.zip file
mvc.iso file
now when i like to search by partial name webapi then i want to get list of files and folders name which has webapi word. i want to show their full folder or file name in grid with their full path and size. like below way.
Name Type location Size
c webapi xx folder c:\test1 2 KB
c mvctutorial xx folder c:\test3 3 KB
done webapi xx folder c:\test1 11 KB
webapi done folder c:\test1 9 KB
webapi.zip file c:\test1 20 KB
mvc.iso file c:\test4 5 KB
i got a sample code which look like for finding files but the below code may not find folder. so i am looking for a sample code which will find files and folders too. so guide me to solve my issue.
the below sample code will find files but not sure does it find files by partial name. here is the code. i am not before dev environment. so could not test the below code.
find files code
static void Main(string[] args)
string partialName = "webapi";
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(@"c:\");
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*");
foreach (FileInfo foundFile in filesInDir)
string fullName = foundFile.FullName;
Console.WriteLine(fullName);

See code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
string partialName = "webapi";
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(@"c:\");
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*");
foreach (FileInfo foundFile in filesInDir)
string fullName = foundFile.FullName;
Console.WriteLine(fullName);
DirectoryInfo[] foldersInDir = hdDirectoryInWhichToSearch.GetDirectories("*" + partialName + "*.*");
foreach (DirectoryInfo foundFolder in foldersInDir)
string fullName = foundFolder.FullName;
Console.WriteLine(fullName);
// or
List<string> filesInDir2 = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*").Select(x => x.FullName).ToList();
filesInDir2.AddRange( hdDirectoryInWhichToSearch.GetDirectories("*" + partialName + "*.*").Select(x => x.FullName).ToList());
foreach (string filesFolders in filesInDir2)
Console.WriteLine(filesFolders);
jdweng

Similar Messages

  • How to move folders and files using UJFS

    Hi guys,
    I need to move from one environment to another the folders and files in the structure, cause the backup / restore (UJBR) doesn't move that part, now I need to know how to do it in the transaction UJFS . ( I'm using SAP BPC 7.5 NW Patch 8)
    Thanks for your help.
    Cheers,
    Rodrigo

    Thanks for your answer,
    In this case, I'm going to move the files and folders from one server to another, so it's not the scenario you mentioned.
    Cheers,
    Rodrigo

  • How to delete Folders and Files older than 10 day ?

    If I use this below command, I am able to delete only the files and files in sub-folders older than 10 day,
    forfiles /p "D:\Testing\Sample" /s /d -10 /c "cmd /c del /s /q @file"
    Please help...
    Thanks

    Hello Raman459,
    please see this blog entry:
    http://elderec.org/2012/02/scripting-delete-files-and-folders-older-than-x-days/
    Your command is ok for files, for folders you need to do another command:
     forfiles -p "D:\Testing\Sample" -d -10 -c "cmd /c IF @isdir == TRUE rd /S /Q @path"
    If this post solved your question, please mark as an answer, or if it helped your quest, please vote as helpful. Thank you.
    Thank you,
    F. Schubert
    System Administrator
    MCP | Microsoft Certified Professional
    MCTS 70-640 | Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    MCTS 70-642 | Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    MCTS 70-643 | Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuring
    MCTS 70-680 | Microsoft Certified Technology Specialist: Windows 7, Configuration

  • How to recover lost folders and files - Pls help, help...

    Some days ago I lost all of my 15 GB folders and files that stored in my Macbook Pro hard drive called DATA.  I brought my Macbook pro to an experienced computer tecnicians who providing data recovery services. To his and my suprise, after checking, scanning it a few hours, he said their is no way to recover because he did not find any trails at all.  The computer still seems working properly - I have no problem with any applications.  There are few other folders in the DATA hard disk containing pictures, computer programs still remain.  These lost folders and files contain mainly documents (word, excel, power point, pdf etc) which I accumulated in my many years working  !!!!.  I did not make a back up since last September partly because I think Mac is very safe.
    The computer with me all the time on that day and only my son used Power Point to make a simple presentation on that evening - he can not save it on the folders the he normally use - All the folders and files are gone.
    I will appreciate it very much if any of you can tell me what would be the possible causes and more importanly how to recover the lost folders and files.  They are very very valuable to me.
    Many thanks for your kind attention
    Loimekong from Vietnam
    Macbook Pro 2.4 Ghz
    Intel Core 2 Duo
    4 GB 1067 MhZ DDR3

    First, did the data actually get deleted, or is it still there somewhere?  Try searching the drive for some of the documents, perhaps it's all just in another folder on that drive.
    If it's truly gone, it's impossible for us to say what might have happened to make it unrecoverable.  Perhaps someone using the computer used Secure Empty Trash, or securely erased empty space on the hard drive.  Perhaps it was overwritten by other stuff before you noticed.  It's possible the hard drive is starting to fail, though this seems like an awfully specific problem for that to be the issue.
    Or perhaps the tech you took the computer to didn't know what he was doing.  Why not try recovering what you can on your own?  See Recovering deleted files.
    You should be aware that no computer is safe.  All computers rely on hardware that may fail and software that can have bugs.  You absolutely MUST maintain a good set of frequently-updated backups...  no fewer than two full backups of anything you don't want to lose.
    (Note that my pages contain links to other pages that promote my services, and this should not be taken as an endorsement of my services by Apple.)

  • Formatted HD, but have backup of all the folders and files of Firefox. How can I restore everything, including plugins, bookmarks and saved settings?

    I have formatted my computer's HD because of a problem with Windows 7, the thing is that Windows 7 didn't start, so I couldn't backup my Firefox settings, bookmarks, plugins, themes, personas and etc. the right way.
    I also don't have a Firefox Sync account.
    What I do have are all the folders and files of Firefox, because I just created a new partition and installed Windows 7 again, what I'm having trouble is finding a way (if there's any) to restore everything from my previous installation to the new one.
    I have searched for days on both Google and on te Firefox forum with no success, the only questions I found are about restoring a profile, but what I'm trying to do is the same thing that the Firefox add-on " FEBE " does, which is restoring everything to the previous configuration.
    Here's alink to the add-on: https://addons.mozilla.org/pt-br/firefox/addon/febe/
    I have tried copying, pasting and overwritting from the " .default " folder to my new installation of Firefox (yes, Firefox was closed), but when I opened it again, nothing was restored.
    I every single folder and file Firefox ever created on my computer, this includes the installation folder (at Program Files), the profile (.default at AppData) folder, the Mozilla folder (ProgramData) and the Mozilla Firefox folder (also at AppData).
    I also had the FEBE add-on installed, but like stated before, unfortunately I couldn't start Windows 7, forcing me to create a new partition to install a new copy of the OS.
    Thanks in advance.
    PS. Sorry if I made the text too long and/or if I mentioned the same things twice, just trying to be thorough.

    Hi Sdarts,
    I apologize for the delay in replying to your question, and I am sorry to hear that you are having issues restoring your Firefox user data.
    Please see the following article, which explains how to restore your Firefox user data using a previously backed up Profiles folder, which seems to apply to your situation:
    * [https://support.mozilla.org/en-US/kb/back-and-restore-information-firefox-profiles Backup and Restore information from Firefox Profiles]
    Please let us know if this solves your problem or if you have any questions.
    Thanks!!
    - Ralph

  • Sorting folders and files in FINDER

    I can sort folders and files alphabetically, chronologically, etc using LIST view, but not in any other view.
    I seem to recall that FINDER used to sort alphabetically but now seems to sort randomly. I prefer to use the COLUMNS view.
    In LIST view there are column headers NAME, DATE MODIFIED, SIZE, KIND and clicking on one will sort accordingly.
    But these headers do not appear in the other views.

    Hi,
    This can be done. If you want to arrange your files etc as columns...select "As Columns" from the "View" menu & then select "View Options" also from the "View" menu. It will then give you options as to how you wish to arrange your files etc.
    Ben

  • How to print a list of the folders and files in a higher level folder?

    I want to print out a list of the files that I have in a folder. It contains a nested series of folders with files in each. I want to print a list of folders and files in the same order that I see them on the screen. I'm seeing them in the finder in List format.
    If I select all, copy, then paste into a word processor, I get all the files and folder names reorganized alphabetically, which I don't want. Also, I don't get the file size or date modified when I do this.
    I'd prefer not doing 30+ screen shots then having to print them all individually.
    Any suggestions?
    Thanks,
    Brad

    There is also DiskCatalogMaker (http://diskcatalogmaker.com/) even better than PrintWindow in my estimation

  • How to create a folder with standard contained folders and files in SharePoint 2013?

    I've got folders and files on my SharePoint 2013 site that form a template when I add a new folder for a customer. When I create a new folder for a customer, I want those folders and files added automaticly to that new folder. How can I do that?

    How would I go about doing this without Visual Studio? Is that possible? Need to create Folder templates.
    Every "new folder" created should have nested folders already included. 
    Company Name (New Folder 1) 
    Company Documents (1.01)
    Tax Documents (1.02)
    Bank Statements (1.03)
    Extreme novice, please give as much details as possible! I'm trying to implement SP 2013 without all the 2013 software (Visual Studios, SharePoint Designer, etc.)
    Thank you!

  • Finder not able to view folders and files on EHD after updating to OS X 10.9.4

    I can see still see 'Hitachi' in the 'Devices' Sidebar, but I am not able to view folders and files on this Hitachi XL2000 2TB FAT32 Hard Drive (EHD) that is USB connected to the iMac below.
    Late 2013 Apple iMac (27-inch Display 2560 x 1440), 3.4GHz Quad-core Intel Core i5, Turbo Boost up to 3.8GHz, 8GB 1600MHz DDR3 SDRAM - 2X4GB, 512GB Flash Storage, NVIDIA GeForce GTX 775M 2GB GDDR5, Magic Trackpad, Apple Wireless Keyboard and OS X 10.9.4 Mavericks
    All was fine until I updated from OS X 10.9.3 to 10.9.4 earlier this week, so now when I double-click on 'Hitachi' it just loads and loads with nothing happening and never displays the folder and file contents of the EHD.
    Also, confirmed that Hitachi EHD has been removed from Spotlight indexing per System Preferences > Privacy > + > Hitachi and it was so this does not seem to be an indexing issue.
    I have used OnyX and Apple Disk Utilities unsuccessfully to try and fix this problem.
    Interestingly, Backblaze online backup still sees the EHD and connecting this EHD to a Win 8.1 PC also sees the EHD.
    Further, I ran the commands below in 'Terminal' to make sure the drive was visible and got the following results which shows that the EHD is not hidden.
    iMac:Applications john$ chflags nohidden /Volumes/Hitachi/
    iMac:Applications john$ GetFileInfo /Volumes/Hitachi/
    directory: "/Volumes/HITACHI"
    attributes: avbstclinmedz
    modified: 07/10/2014 23:26:44
    Finally, I installed XtraFinder and am still not able to see the contents of the EHD, but when I installed OmniDiskSweeper I can navigate the EHD folder tree with no problems and can see the contents of the EHD, but when I try and open up a file it opens Finder which loads and loads and nothing happens.

    Apple Support was quite helpful, but in the end I will wait to do a clean install of OS X Yosemite which is due in the Fall and not try and fix OS X 10.9.4 Mavericks.
    It turns out that I run backups on my '/Users/john/Library' and the size of this folder before the 10.9.4 update was 1.07 GB and after the update it is 806.9 MB which is baffling, but in the end all of these problems should be resolved with a clean install of OS X Yosemite.
    One lesson learned for the future is that I will wait on installing an update until it has been in the wild for awhile as a quick OS X Mavericks Finder Problem search and similar searches show there could be an issue.

  • How to find PG.xml file name and path associated with a FUNCTION

    Hi,
    I am having a function:IRC_VIS_HOME_PAGE with Web HTML value as below:
    OA.jsp?akRegionCode=IRC_VIS_HOME_PAGE&akRegionApplicationId=800&OAPB=IRC_BRAND
    How to find PG.xml file name and path assoicated with above funtion.
    Thanks,
    ashok

    Ashok,
    Function IRC_VIS_HOME_PAGE will have 2 parameter defined for it which are OASF and OAHP where
    OASF=<SelectedFunctionName> - this tells the Framework to select this function in the given "Home Page" menu context.
    OAHP=<HomePageMenuName> - this is used ONLY with the OASF parameter, and it is used to establish the current menu context. It should point to a "Home Page" menu.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can I explore the folders and files on my phon...

    How can I explore the folders and files on my phone from my phone (lumia 920)?

    the file system including all the data pertaining to that partition is closed on windowsphone8, unlike that of Symbian.
    the only part you will be able to see is what you would see in this post here: /t5/Nokia-Lumia/Transfer-file-for-920/m-p/1605954#M24335
    the rest is locked unless you have developer access, and even then not much as you would just use the SDK to make your applications.

  • How get SharePoint Library Folders and Files directory structure in to my custom web site.

    Hi,
    Actually my requirement is, I would like to pass site name and document library name as a parameter and get a folders and files from the document library and form the directory structure by using Treeview control in my web site.
    How should i get? Using Web service / object model?
    Web service would return the dataset as a result so from that how could i form the directory structure using Treeview control.
    I will select specified files and folders then i ll update sharepoint document library columns for corresponding selected files.
    Can anyone help over this, that would be great appreciate.
    Thanks in Advance.
    Poomani Sankaran

    Hello,
    Here is the code to iterate through sites and lists:
    //iterate through sites and lists
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using (SPSite site = new SPSite(webUrl)) {
    using (SPWeb oWebsite = site.OpenWeb())
    SPListCollection collList = oWebsite.Lists;
    foreach (SPList oList in collList)
    {//your code goes here }
    Then use RecursiveAll to get all files and folders.
    http://www.codeproject.com/Articles/116138/Programatically-Copy-and-Check-In-a-Full-Directory
    http://sharepoint.stackexchange.com/questions/48959/get-all-documents-from-a-sharepoint-document-library
    Here is the full code:
    http://antoniolanaro.blogspot.in/2011/04/show-document-library-hierarchy-in-tree.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Finder is not displaying some folders and files

    Most folders and files are displaying properly, but some are missing.  I can find them by typing their names into the search window, but they are not displaying automatically in Finder.

    Hello Andy_fan
    Please look for MS-SMB_ServerUserGuide.docx file in the folder where you extracted MS-SMB.zip file and refer section 'Configure the SUT' for configuring SUT. Follow other relevant sections of this document to configure client as well.
    Domain is not a requirement for running SMB test suite, hence, if you are in workgroup environment just ignore domain values in the
    ParamConfig.xml
    file.
    Thanks
    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

  • I cannot view folders and files in finder on macbook pro OS version 10.9.5. Why it happens and what should I do about it?

    I cannot view folders and files in finder on macbook pro OS version 10.9.5. Why it happens and what should I do about it?

    Please post a screenshot that shows what you mean. Be careful not to include any private information.
    Start a reply to this message. Drag the image file into the editing window to upload it. You can also include text in the reply.

  • Finder has stopped putting my folders and files in alpha order.  What happened?

    Finder has stopped putting my folders and files in alpha order.  What has happened?

    When you check and reset that file setting back to alphabetical order, does it stick?
    Sometimes a user permissions issue may cause a slight problem, so if this is the
    only issue, you could try to 'repair disk permissions' in Disk Utility, However if there
    is some other problem and this is only a symptom, something else may be the cause.
    If files have been moved between user accounts, then previous account settings &
    user permissions may be included with the moved file, so this matter may require
    you to look into the settings within each file, via Get Info on the highlighted file name.
    You can change permissions and privileges to some extent within this area.
    And at times, a simple restart may be required, if the unit has been on awhile. Given
    a portable computer, unlike a desktop, your use may not include leaving it on for
    months at a time; so it probably has been restarted more than occasionally. Mine,
    set to automatically sleep & spin-down the HDD when not in use, is up for months.
    Good luck & happy computing!

Maybe you are looking for