Need To Get Folder and Subfolders List

Hi All
I have a requirement which will give me the list of folder and subfolders list for a given path. I can achieve this using xp_cmdshell.
But it is admin level usage. So i need to get with the use SP_OAMethod using file system object.
Please help me to do the same.

Hello Amarnath, Finally i have the code that you are looking for. 
SELECT * FROM dbo.dir('c:\testfolder') WHERE IsFolder =1
--------------- USER DEFINE FUNCTION
CREATE FUNCTION [dbo].[Dir](@Wildcard VARCHAR(8000))
RETURNS @MyDir TABLE
-- columns returned by the function
[name] VARCHAR(2000), --the name of the filesystem object
[path] VARCHAR(2000), --Contains the item's full path and name.
[ModifyDate] DATETIME, --the time it was last modified
[IsFileSystem] INT, --1 if it is part of the file system
[IsFolder] INT, --1 if it is a folsdder otherwise 0
[error] VARCHAR(2000) --if an error occured, gives the error otherwise null
AS
-- body of the function
BEGIN
DECLARE
--all the objects used
@objShellApplication INT,
@objFolder INT,
@objItem INT,
@objErrorObject INT,
@objFolderItems INT,
--potential error message shows where error occurred.
@strErrorMessage VARCHAR(1000),
--command sent to OLE automation
@Command VARCHAR(1000),
@hr INT, --OLE result (0 if OK)
@count INT,@ii INT,
@name VARCHAR(2000),--the name of the current item
@path VARCHAR(2000),--the path of the current item
@ModifyDate DATETIME,--the date the current item last modified
@IsFileSystem INT, --1 if the current item is part of the file system
@IsFolder INT --1 if the current item is a file
IF LEN(COALESCE(@Wildcard,''))<2
RETURN
SELECT @strErrorMessage = 'opening the Shell Application Object'
EXECUTE @hr = sp_OACreate 'Shell.Application',
@objShellApplication OUT
--now we get the folder.
IF @HR = 0
SELECT @objErrorObject = @objShellApplication,
@strErrorMessage = 'Getting Folder"' + @wildcard + '"',
@command = 'NameSpace("'+@wildcard+'")'
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objShellApplication, @command,
@objFolder OUT
IF @objFolder IS NULL RETURN --nothing there. Sod the error message
--and then the number of objects in the folder
SELECT @objErrorObject = @objFolder,
@strErrorMessage = 'Getting count of Folder items in "' + @wildcard + '"',
@command = 'Items.Count'
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objfolder, @command,
@count OUT
IF @HR = 0 --now get the FolderItems collection
SELECT @objErrorObject = @objFolder,
@strErrorMessage = ' getting folderitems',
@command='items()'
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objFolder,
@command, @objFolderItems OUTPUT
SELECT @ii = 0
WHILE @hr = 0 AND @ii< @count --iterate through the FolderItems collection
BEGIN
IF @HR = 0
SELECT @objErrorObject = @objFolderItems,
@strErrorMessage = ' getting folder item '
+ CAST(@ii AS VARCHAR(5)),
@command='item(' + CAST(@ii AS VARCHAR(5))+')'
--@Command='GetDetailsOf('+ cast(@ii as varchar(5))+',1)'
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objFolderItems,
@command, @objItem OUTPUT
IF @HR = 0
SELECT @objErrorObject = @objItem,
@strErrorMessage = ' getting folder item properties'
+ CAST(@ii AS VARCHAR(5))
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objItem,
'path', @path OUTPUT
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objItem,
'name', @name OUTPUT
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objItem,
'ModifyDate', @ModifyDate OUTPUT
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objItem,
'IsFileSystem', @IsFileSystem OUTPUT
IF @HR = 0
EXECUTE @hr = sp_OAMethod @objItem,
'IsFolder', @IsFolder OUTPUT
--and insert the properties into a table
INSERT INTO @MyDir ([NAME], [path], ModifyDate, IsFileSystem, IsFolder)
SELECT @NAME, @path, @ModifyDate, @IsFileSystem, @IsFolder
IF @HR = 0 EXECUTE sp_OADestroy @objItem
SELECT @ii=@ii+1
END
IF @hr <> 0
BEGIN
DECLARE @Source VARCHAR(255),
@Description VARCHAR(255),
@Helpfile VARCHAR(255),
@HelpID INT
EXECUTE sp_OAGetErrorInfo @objErrorObject, @source OUTPUT,
@Description OUTPUT, @Helpfile OUTPUT, @HelpID OUTPUT
SELECT @strErrorMessage = 'Error whilst '
+ COALESCE(@strErrorMessage, 'doing something') + ', '
+ COALESCE(@Description, '')
INSERT INTO @MyDir(error) SELECT LEFT(@strErrorMessage,2000)
END
EXECUTE sp_OADestroy @objFolder
EXECUTE sp_OADestroy @objShellApplication
RETURN
END---- OUTPUT
Regards, RSingh

Similar Messages

  • How to count files in a folder and subfolders of the folder.

    Hello everyone,
    I'm having a difficulty with countin files in a Regular folder and subfolders of the folder. I've tried to use SI_ANCESTOR  in a query; however, it gives me innacurate results.
    I used this hierarchy to create the code below, and it works to count all the files:
    Folder A ---> Folder B( subFolder of A)  -
    > Folder C(subFolder of B)  
    //get folder A
    IInfoObjects regFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND='Folder' AND SI_PARENTID=0 AND SI_NAME!='User Folders' Order by SI_NAME");
    IFolder regFolder = (IFolder) regFolders.get(0);     
    //get files from Folder A     
    IInfoObjects rFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID !   = 'CrystalEnterprise.Folder'   AND SI_PARENTID=" + regFolder.getID() );
    ilesCount += rFiles.size();
    int subCntr=0;
    nt subCntr2=0;
      //get folder B      
    IInfoObjects rSubFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + regFolder.getID() );
    //get files from subFolders of Folder A
    while (subCntr < rSubFolders.size())
              IInfoObject subFolder=(IInfoObject)rSubFolders.get(subCntr);
              IInfoObjects subFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "
          + " WHERE SI_PROGID != 'CrystalEnterprise.Folder'" AND SI_PARENTID=" + subFolder.getID() );
             filesCount += subFiles.size();
             //get subFolders of Folder B                   
             IInfoObjects rSubFolders2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + subFolder.getID() );
                         //get files from subFolders of Folder B
         while (subCntr2 < rSubFolders2.size())
              IInfoObject subFolder2=(IInfoObject)rSubFolders2.get(subCntr2);
              IInfoObjects subFiles2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "
                   + " WHERE SI_PROGID != 'CrystalEnterprise.Folder'  AND SI_PARENTID=" + subFolder2.getID() );
                                               filesCount += subFiles2.size();
               subCntr2++;
              subCntr++;
    As you can see, the code is too complicated, and what if folder C has subFolder?
    I'm guessin maybe recursion would be one way to got, but I'm not really good with it, so I was wondering if anyone has any idea on how to go about doing it.
    Thank you,

    Hi,
    For detailed information, please refer to the BI 4.0 developers guide here.
    You can find the section "Setting up the development environment" in developers guide that have every single instruction to execute a java code specific to BI 4.0 environment.
    Also, here are the instructions for BO 3.1 environment:
    To configure a WAR file for a J2EE application that uses the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK, complete these steps:
    Create a lib folder in the WAR file's WEB-INF folder.
    Copy the Enterprise XI 3.0 or 3.1 Java SDK JAR files from the appropriate location below to the WAR file's WEB-INF\lib folder:
    Windows:
    ...\Program Files\Business Objects\common\4.0\java\lib
    UNIX:
    <businessobjects_root>/java/lib
    Copy the log4j.jar file from the appropriate location below to the WAR file's WEB-INF\lib folder:
    Windows:
    ...\Program Files\Business Objects\common\4.0\java\lib\external
    UNIX:
    <businessobjects_root>/java/lib/external
    Copy the entire crystalreportviewers12 folder from the appropriate location below to the WAR file's root folder.
    Windows:
    ...\Program Files\Business Objects\common\4.0
    UNIX:
    <businessobjects_root>/enterprise12/JavaSDK
    Open the web.xml file located in the WAR file's WEB-INF folder.
    Specify the location of the utility files used by the report viewers contained in the crystalreportviewers12 folder by inserting the following code below the <display-name> and <description> tags but within the <webapp> tag definition:
    <context-param>
    <param-name>crystal_image_uri</param-name>
    <param-value>/BOXIR3/crystalreportviewers12</param-value>
    </context-param>
    <servlet>
    <servlet-name>CrystalReportViewerServlet</servlet-name>
    <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>CrystalReportViewerServlet</servlet-name>
    <url-pattern>/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>
    Deploy the WAR file to the J2EE application server.
    You are now able to run an application using the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK on a J2EE web application server.
    Hope it helps.
    Regards,
    Anchal

  • WS-security Need to Get Username and Password and time Stamp in SOAP Header

    HI ALL,
    i need to get USERNAME and PWD in my Soap header for consuming Webservice using SAP PI ,
    and my SOAP Header should look like this
    <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-
    1.0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-
    secext-1.0.xsd">
    <wsu:Timestamp wsu:Id="Timestamp-296915943">
    <wsu:Created>2008-06-05T18:30:59.904Z</wsu:Created>
    <wsu:Expires>2009-06-05T18:35:59.904Z</wsu:Expires>
    </wsu:Timestamp>
    <wsse:UsernameToken wsu:Id="UsernameToken-192809888">
    <wsse:Username>midtier-service</wsse:Username>
    xxxxxxxx: Confidential Green 10
    <wsse:Password Type="http://docs.oasisopen.
    org/wss/2004/01/oasis-200401-wss-username-token-profile-
    1.0#PasswordText">password</wsse:Password>
    </wsse:UsernameToken>
    </wsse:Security>
    </soapenv:Header>
    should i need to get some certificates from client and deploy it or should we do anything in SAP PI and send to soap header or can hard code it and send to webservice, please help me in this t
    hanking you
    Sridhar

    i need to get USERNAME and PWD in my Soap header for consuming Webservice using SAP PI ,
    Can be achieved by XSL Mapping or SOAP Axis Adapter. Search on SDN for further details as this has been discussed many a times on the forum.
    should i need to get some certificates from client and deploy it or should we do anything in SAP PI and send to soap header or can hard code it and send to webservice, please help me in this t
    First you need to confirm whether certificates are required or not. Might be the web service is using user id / password security (basic authorization).
    How to use certificates in PI - Search on SAP Help, this has been explained in great details over there.

  • I have tried to update my iphone 3gs and i need to get ios5 and when i click on check for updates it says that itunes can not be contacted and check my internet connection but i have internet? how else can i get ios5 on my phone?

    i have tried to update my iphone 3gs and i need to get ios5 and when i click on check for updates it says that itunes can not be contacted and check my internet connection but i have internet? how else can i get ios5 on my phone?

    edit the hosts file on your computer and remove any lines that contain gs.apple.com. Disable your antivirus and firewall.

  • What's up with this update re: Java? Do I have it?  If not, do I need to get it and from where?

    What's up with this update re: Java?
    Do I have it? 
    If not, do I need to get it and from where?
    Thanks

    You don't have it unless you have downloaded and installed it either manually or via Software Update.
    The update should be installed to protect you from possible malware exploits via Java. However, if you don't use Java programming or run Java applets in your browser, then you do not need the update. But you must turn Java off in your browser's security preferences (it will be a checkbox.)

  • Is Adobe Photoshop cs3/10 still being supported?  Mac crashed and need to get up and running again.

    Is Adobe Photoshop cs3/10 still being supported?  Mac crashed and need to get up and running again.  Thank you for any info on cs3. mayord

    I believe if you were to ask Adobe Support they would tell you that CS3 is no longer supported by their services, if that is what you are refering to when you say "being supported".  That means they are not likely to offer assistance with you re-establishing it.
    But you can probably re-establish it yourself.  If you need to download it there is a place for that available:
    You can download the trial version of the software thru the page linked below and then use your current serial number to activate it.
    Be sure to follow the steps outlined in the Note: Very Important Instructions section on the download pages at this site and have cookies enabled in your browser or else the download will not work properly.
    CS3 and CS4: http://prodesigntools.com/download-adobe-cs4-and-cs3-free-trials-here.html

  • Need code to search through folder and subfolders

    Hi.....
    Am trying to write a program to search for a file through folder and all of its sub folders.
    I tried my best but i was able to search through a folder but not through its sub folders.
    So, anyone could help me out with the code to do this operation?
    Regards
    codingquest

    codingquest wrote:
    Thank you very much for your reply.
    I tried to use the recursive call but i could not do it without any errors.
    So it would be helpful to me if you post the exact coding or the key part of the recursive call here.You'd get better response when you post your code and the error message(s). I'm sure someone will be able to point you in the right direction.

  • Comparing count and combined file sizes of specific file types in target folder and subfolders

    Hi all,
    I have a script that I use to delete files with a certain file extension in a folder and its subfolders. I would like to enhance to the script by counting the total number of files and their combined size in MB that the script is deleting and use this information
    in a popup where a message will say something like "X No. Files deleted totalling YMB
    The existing script so far is:
    get-childitem  -include *.****.rfa -recurse | foreach ($_) {remove-item $_.fullname}
    Can any advise what I need to add as I'm quite new to powershell.
    Thanks

    So you do not know how to write a simple output statement.  I think you need to start here:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    Not specifically within Powershell no, like I said I only started looking at it this week as an alternative to VBS.
    Nothing is being declared.  You need to learn the basics of PowerShell.  We cannot teach you one line at a time.
    Really? So the author of
    this website is talking rubbish is he? ("Once data is assigned to a PowerShell variable, it’s automatically declared.")
    I never asked for line-by-line hand holding nor am I someone who wants others to write the entire code for me. Examples of previous scripts that perform similar or partial operations would have been a good way to guide a new user unfamiliar to this topic.
    Additionally posting modified(incorrect) and unfinished script examples without clearly stating what your code is doing nor that additional lines of code need to be added before the script will operate as outlined in the original post is confusing to someone
    with 0 experience in this area.
    On forums I frequent that are relevant to subjects which I have good experience with, whenever I respond to a genuine query of that has an example of what they are trying to create/modify, I will happily provide a full example and/or explain what I
    have done so the OP understands exactly what I did to achieve their request in my example. For someone with your points tally (and likely a respected poster amongst your peers on this site) responding with what is essentially "RFTM Noob" I trust you can understand
    is somewhat disappointing.

  • WP 8.1 LiveSDK 5.5 get folder and create folder issue on some devices

    Hi,
    I've an app which will connect to the users OneDrive account and creates a folder and upload a textfile.
    1. I check if a specifig folder exists, and if it exists, I'll get the folder ID.
    LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files?filter=folders");
    foreach (var item in operationResult.Result.Values.ToList())
    foreach (IDictionary<string, object> fo in (item as List<object>))
    if (fo["name"].ToString() == folderName)
    return fo["id"].ToString();
    If the ID is null, I'll create the folder with this piece of code...
    await client.PostAsync("me/skydrive", new Dictionary<string, object>() { { "name", "MyFolderName" } });
    My issue... this won't work on any windows phone device.
    This will work on my device Lumia 925 with WP 8.10.12393.890 one device where this won't work is a Lumia 830 with WP 8.10.14219.0
    I'll will get these error messages from some customers:
    "The resource couldn't be created because a resource named 'MyFolderName' already exists." or "Input parameter 'path' is invalid.  'path' must be a valid URI."
    So what could be my issue? Can anyone help me with this.
    In my develeopment environment I just updated to LiveSDK 5.6 and it will work on my Lumia 925 device. Could this a soloution for my issues? (It's not uploaded to the app store with this change).
    I'm greatful for any hint or solution.
    Kind regards
    Kevin

    Hey
    Thanks for reaching out to us on the community and welcome aboard. I hope you find all the answers you were hoping for (Though we're not sure of the meaning of life just yet) ;)
    In regards to your troubles, the best place to start would be with a clean reinstall of the app. It will make sure that any faulty cache data etc. will be removed. Find instructions on how to do so here:
    https://support.spotify.com/learn-more/faq/#!/article/reinstallation-of-spotify
    Of course, get back to me and let me know how it all goes. I'd love to help out should you need me more.
    Thanks! :)

  • Event Receiver to get folder Names from List View Web Part

    Hi,
    We have a requirement i.e.
    On one of the page,there are some folders on the list view web part.
    Now through event receiver i should pick the folder names from list view web part and
    update the same in the list.
    If that names already exists in the list then we should leave without updating,if not we have to add folder name in the list.
    Please share your ideas regarding the same.
    Regards,
    Naga Sudheer M
    Thanks & Regards, Sudheer

    Hello,
    LVWP is just for displaying content of site so you need to associate your event receiver with actual list/library. You can create ItemAdded event receiver to check existing folder and create new if not existing. "sk2014" links are good to start.
    http://sharepoint.stackexchange.com/questions/59788/change-name-in-itemadding-event-receiver-or-create-a-new-item
    Let us know in case any doubt
    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

  • I want to transfer my photos from the PC (windows explorer) to my Ipad. The problem is that a keep my photos i different categories and they are in one large folder and subfolders (2 or 3 levels of subfolders).When I sent it to the Ipad, it just respect t

    I want to transfer my photos from the PC (windows explorer) to my Ipad. The problem is that a keep my photos in different categories and they are in one large folder and several subfolders (2 or 3 levels of subfolders).When I sent it to the Ipad, it just respect the first level of folder. After the first subfolder, all the photos are mixed. Any idea how to keep my original organization just transferring from PC to the Ipad (folder having a subfolder also having another subfolder)?
    Thanks
    Diogo

    The Photos app doesn't currently support subfolders, it only has the one level of folder/album. You will either need to change your folder structure on your computer to be just one level, see if there is a third-party photo app in the store that copes with subfolders, or just make do. You can try leaving feedback for Apple : http://www.apple.com/feedback/ipad.html

  • Download a Folder and subfolders?

    Is there a simple way for an AIR app to download an entire
    folder and it's contents from a web sever and copy it to the local
    file system?
    There are lots of articles on downloading files, and ways to
    detect the contents of folders but nothing I can find on entire
    folders.

    Hi,
    There's no simple way. You'd need some way to figure out the
    contents of a folder on the web server (if you don't have an
    index.html, some web servers by default serve a html page listing
    all the contents) and download each one and also recurse when you
    encounter another folder.

  • Concern with "File Sharing: On" -- my root user folder (and subfolders) and Macintosh HD is visible

    Hi all,
    When I set up a File Sharing folder in OSX called "Share", I connected from my PC to my Macbook Pro and not only did I see the "Share" folder but I also could see and have total access to my root user folder (all its subfolders too) and my Macintosh HD (hard disk).  Did I miss something?  All I did was check mark "File Sharing" in the Sharing option of System Preferences.  Then I specifically shared only the "Share" folder that I created on the OSX desktop.
    How do I turn of sharing for the root user folder and my Macintosh HD folder?
    Many thanks in advance!

    Yes, I was logging in from my PC laptop to Mac as the Admin.  However, since there is a User called "Everyone" and I, for testing purposes only, turned Read/Write on for "Everyone", I figured I did not have to set up another user (such as "Guest").  I was wrong.  Once I created a new user called "Guest" and specifically checked the Guest account in the SMB option, it worked in the restricted mode I was hoping for.  Thanks!

  • I NEED TO GET LOGIN AND LOGOUT TIMING DETAILS FROM CLIENT SYSTEMS

    HI,
    CAN ANYONE PLEASE HELP ME ON HOW TO GET LOGIN AND LOGOUT , CLIENT EVENT DETAILS FROM CLIENT SYSTEMS ON SERVER 2008 R2.
    THANKS,
    KUMAR.

    You may need to enable active directory Logon/Logoff Audit event.
    The Audit logon events policy records all attempts to log on to the local computer, whether by using a domain account or a local account.
    On Domain Controller, this policy records attempts to access the DC only.
    By using these events we can track user's logon duration by mapping logon and logoff events with user's Logon ID which is unique between user's logon and logoff.
    Please refer to this blog to understand the complete process to audit the successful or failed logon and logoff attempts in the network using the audit policies :
    http://www.lepide.com/blog/audit-successful-logon-logoff-and-failed-logons-in-activedirectory/
    Lepide - Simplifying IT Management

  • Robohelp 8 not working, folder and subfolders deleted

    Hi,
    I am using Robohelp 8. I had worked on some files on Thrusday, generated a .chm output, and saved the source and output files onto our company server. My problem is that when I try to open both the files, the one on my computer and the company server, I get a message saying a particular folder and all the sub-folders within it,are missing from the Project Manager. And I that I should delete them. However, while trying to open Robohelp 8, I get a message saying Adobe Robohelp has stopped working. I also get a message saying a problem has caused the system to close. Windows will notify if a solution is available.
    As far as I know I have not worked on Robohelp since Thursday, 28 Oct. I have not deleted any files (even the one that Robohelp now inidcates are missing).
    Any help or advice about what could have gone wrong, will be really appreciated.
    Thanks,
    Sangeeta

    Hi Peter,
    I applied the patches and my files now seem to work fine.
    Thank you,
    Sangeeta

Maybe you are looking for