How to delete the Folder from sql server 2008

Hi all,
I was trying to delete the folder from sql server 2008 with the below script
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @cmd VARCHAR(8000)
DECLARE @folderName VARCHAR(256) -- filename for backup
SET @folderName = + (CONVERT(varchar(10), GETDATE()-7, 112))  -- 7 days back date folder name
SET @path = 'I:\Backup_Test\' + @folderName -- Folder path
SET @cmd = 'del ' + @path -- Delete
EXEC master..xp_cmdshell @cmd
--Print @cmd
This is not working it was asking the Confirmation (I:\Backup_Test\20100629\*, Are you sure (Y/N)? ) what will i do to the delete the folder.
Thanks,
Prasad R.

I would notice   you that T-SQL does not play well to do things like that. Do not you want using .net language to delete folders?
Old method is
declare @HR int, @CFOLDER varchar(255),@FSO int
    set @CFOLDER='D:\folder\'
    EXEC @HR = sp_OACreate 'Scripting.FileSystemObject', @FSO OUT
    EXEC @HR = sp_OAMethod @FSO, null, 'DeleteFolder', @CFOLDER 
Now regarding to your second question please examine xp_fileexist  system stored procedure
CREATE FUNCTION dbo.fn_file_exists(@filename VARCHAR(300))
  RETURNS INT
AS
BEGIN
  DECLARE @file_exists AS INT
  EXEC master..xp_fileexist @filename, @file_exists OUTPUT
  RETURN @file_exists
END
GO
-- test
SELECT dbo.fn_file_exists('c:\a.txt')
Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

Similar Messages

  • How to delete the folder from easy DMS

    Hi..
    How to delete the Folder once it is created in easy DMS? As i have all the access
    Also how to restrict user from deleting the document from DMS? (Delete document option restriction)
    I want all folder to be gets created with internal number range only.i have define the same for Doc type FOL.
    But when i first log-in into easy dms system ask me do i need to create the folder i clicked on yes and while saving it shows an error that only internal number range is possible.But actually number EDIPUBLICROOTFOLDER  is selected by default and unedited format

    Hi,
    How to delete the Folder once it is created in easy DMS? As i have all the access
    First delete all the DIR's inside the folder using delete button. Later you can delete the Folder.
    Also how to restrict user from deleting the document from DMS? (Delete document option restriction)
    You can control this using authorization objects in DMS.
    Hope this helps.
    Regards,
    Deepak Kori

  • How to only migrate data from SQL Server 2008 to Oracle 11?

    According to our requirement, We need to only migrate data from a SQL Server database to an existed
    Oracle database user.
    1) I tried to do it with SQL Developer 3.0.04 Migration Wizard, But find an issue.
    My SQL Server database name is SCDS41P2, and my Oracle database user name is CDS41P2;
    When I used SQL Developer to do offline move data by Migration Wizard, I found all oracle user
    name in movedata files which gotten by run Migration Wizard
    is dbo_SCDS41P2. If the Oracle user name is not the same as my existed Oracle user name,
    the data can't be moved to my existed Oracle user when I run oracle_ctl.bat in command line window.
    So I had to modify the Oracle user name in all movedata files, but it's difficult to modify them because there are many tables in
    databases. So could you please tell me how to get the movedata files which the oracle user name in them is my
    expected Oracle user name?
    2) I also tried to use the 'copy to Oracle' function to copy the SQL Server database tables data
    to the existed Oracle database user. When clicked 'copy to Oracle', I selected 'Include Data' and 'Replace' option
    But I found some tables can't be copied, the error info is as below:
    Table SPSSCMOR_CONTROLTABLE Failed. Message: ORA-00955: name is already used by an existing object
    Could you please tell me how to deal with this kind of error?
    Thanks!
    Edited by: 870587 on Jul 6, 2011 2:57 AM

    Hi,
    Thanks for you replying. But the 'copy to oracle' function still can't be work well. I will give some info about the table. I also search 'SPSSCMOR_CONTROLTABLE' in the target schema, and only find one object. So why say 'name is already used by an existing object'? Could you please give me some advice? Thanks!
    What is the 'Build' version of your SQL*Developer ?
    [Answer]:
    3.0.04
    - what does describe show for the SPSSCMOR_CONTROLTABLE in SQL*Server ?
    [Answer]:
    USE [SCDS41P2]
    GO
    /****** Object: Table [dbo].[SPSSCMOR_CONTROLTABLE] Script Date: 07/18/2011 01:25:05 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[SPSSCMOR_CONTROLTABLE](
         [tablename] [nvarchar](128) NOT NULL,
    PRIMARY KEY CLUSTERED
         [tablename] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    - what does describe show for the SPSSCMOR_CONTROLTABLE in Oracle ?
    [Answer]:
    -- File created - Monday-July-18-2011
    -- DDL for Table SPSSCMOR_CONTROLTABLE
    CREATE TABLE "CDS41P2"."SPSSCMOR_CONTROLTABLE"
    (     "TABLENAME" NVARCHAR2(128)
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ;
    -- DDL for Index SYS_C009547
    CREATE UNIQUE INDEX "CDS41P2"."SYS_C009547" ON "CDS41P2"."SPSSCMOR_CONTROLTABLE" ("TABLENAME")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ;
    -- Constraints for Table SPSSCMOR_CONTROLTABLE
    ALTER TABLE "CDS41P2"."SPSSCMOR_CONTROLTABLE" MODIFY ("TABLENAME" NOT NULL ENABLE);
    ALTER TABLE "CDS41P2"."SPSSCMOR_CONTROLTABLE" ADD PRIMARY KEY ("TABLENAME")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ENABLE;
    Edited by: 870587 on Jul 18, 2011 1:42 AM

  • How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?

    How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
    I tried using DROP Tables, Truncate Database, Delete and many more but it is not working.  I want to delete all tables using Query Analyzer, i.e. through SQL Query.
    Please help me out in this concern.
    Nishith Shah

    Informative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
    declare @TTName Table
    (TableSchemaTableName
    varchar
    (500),
    [status] int
    default 0);
    with AvailableTables
    (TableSchemaTableName)
    as
    (select
    QUOTENAME(TABLE_SCHEMA)
    +
    +
    QUOTENAME(TABLE_NAME)
    from
    INFORMATION_SCHEMA.TABLES)
    insert into @TTName
    (TableSchemaTableName)
    select *
    from AvailableTables
    declare @TableSchemaTableName varchar
    (500)
    declare @sqlstatement nvarchar
    (1000)
    while 1=1
    begin
    set @sqlstatement
    =
    'DROP TABLE '
    + @TableSchemaTableName
    exec
    sp_executeSQL
    @sqlstatement
    print
    'Dropped Table : '
    + @TableSchemaTableName
    update @TTName
    set [status]
    = 1
    where TableSchemaTableName
    = @TableSchemaTableName
    if
    (select
    count([Status])
    from @TTName
    where [Status]
    = 0)
    = 0
    break
    end

  • If I move a mailbox from my imap account to "on my mac" can I safely delete the folder from the mail server and still be able to read the messages?

    If I move a mailbox from my imap account to "on my mac" can I safely delete the folder from the mail server and still be able to read the messages?

    You certainly can.
    Be aware that the emails you move to local storage ("on my Mac") will be the only copies that remain.

  • How to delete the data from partition table

    Hi all,
    Am very new to partition concepts in oracle..
    here my question is how to delete the data from partition table.
    is the below query will work ?
    delete from table1 partition (P_2008_1212)
    we have define range partition ...
    or help me how to delete the data from partition table.
    Thanks
    Sree

    874823 wrote:
    delete from table1 partition (P_2008_1212)This approach is wrong - as Andre pointed, this is not how partition tables should be used.
    Oracle supports different structures for data and indexes. A table can be a hash table or index organised table. It can have B+tree index. It can have bitmap indexes. It can be partitioned. Etc.
    How the table implements its structure is a physical design consideration.
    Application code should only deal with the logical data structure. How that data structure is physically implemented has no bearing on application. Does your application need to know what the indexes are and the names of the indexes,in order to use a table? Obviously not. So why then does your application need to know that the table is partitioned?
    When your application code starts referring directly to physical partitions, it needs to know HOW the table is partitioned. It needs to know WHAT partitions to use. It needs to know the names of the partitions. Etc.
    And why? All this means is increased complexity in application code as this code now needs to know and understand the physical data structure. This app code is now more complex, has more moving parts, will have more bugs, and will be more complex to maintain.
    Oracle can take an app SQL and it can determine (based on the predicates of the SQL), which partitions to use and not use for executing that SQL. All done totally transparently. The app does not need to know that the table is even partitioned.
    This is a crucial concept to understand and get right.

  • Copy the data from Sql Server to edirectory using java

    Hi ,
    I am new to e directory.I don't know how it works.Can some one assist
    me on this ,I have to extract data from SQL Server and update these
    data in edirectory.This is needs to be done using java.
    If any one can provide me the sample code or please suggest how to
    proceed .
    Thanks in advance
    dukewarm
    dukewarm's Profile: http://forums.novell.com/member.php?userid=53430
    View this thread: http://forums.novell.com/showthread.php?t=373051

    dukewarm;1792481 Wrote:
    > Hi ,
    >
    > I am new to e directory.I don't know how it works.Can some one assist
    > me on this ,I have to extract data from SQL Server and update these
    > data in edirectory.This is needs to be done using java.
    >
    > If any one can provide me the sample code or please suggest how to
    > proceed .
    >
    > Thanks in advance
    Read the values from SQL server and use LDAP to update the data in
    eDirectory.
    Thomas
    thsundel
    thsundel's Profile: http://forums.novell.com/member.php?userid=128
    View this thread: http://forums.novell.com/showthread.php?t=373051

  • How to access Oracle 8g from SQL Server 2005 SP3 EE 64 Bits ?

    Dear All,
    How to access Oralce 8g from SQL Server 2005 SP3 EE 64 Bits (liked server).
    Best regards,
    Miguel Gavinhos

    Hi!
    For the Oracle version is 8.1.6. what should I install, to access Oracle trought a linked server.
    Best regards
    Miguel Gavinhos

  • How to delete photostream folder from camera roll on iphone 4

    How to delete photostream folder from camera roll on iphone 4

    Since this is a user to user help forum only, no one here knows. If to be included with the next firmware update and a fellow user is privileged to this info in advance, they aren't allowed to say.
    If you didn't want a photo or photos transferred from your computer to your iPhone in the first place, why did you transfer the photo or photos? And since you should be syncing your iPhone with iTunes often, what difference does it make? If you need space on your iPhone for some reason, you can delete a movie direct from your iPhond that was transferred from your iTunes library to free up much more space with a single swipe than a few photos that you chose to be transferred from your computer.

  • How to Delete the dimension from the cube ?

    Hi ,
    how to Delete the dimension from the cube ?
    i have added the new dimension by assiging one characteristic to that dimension .
    now i  want to delete it ,
    but system saying that   Dimension ZXXX  contains InfoObjects; deletion not possible .
    how to delete it ? any help .
    Thanks

    Make sure you donot have any data in cube. If you have some data in cube, then you will not be able to see Delete option.
    Right click on the cube-->Delete data.
    Then double click on the cube>Goto Edit mode> select the IO under that Dimension> right click> now you will be able to see the Delete option (provided you have deleted all the date from Cube)
    Then right click on Dimension-->Delete
    Regards,
    Pavan

  • System exception while deleting the file from app server in background job

    Hi All,
    I have a issue while the deleting the file from application server.
    I am using the statement DELETE DATASET in my program to delete the file from app server.
    I am able to delete the file from the app server when i run the program from app server.
    When i run the same report from background job i am getting the message called System exception.
    Is there any secuirity which i need to get the issue.
    Thank You,
    Taragini

    Hi All,
    I get all the authorization sto delete the file from application serever.
    Thing is i am able to run the program sucessfully in foreground but not in the background .
    It i snot giving any short dump also just JOB is cancelled with the exception 'Job cancelled after system exception ERROR_MESSAGE'.
    Can anybody please give me suggestion
    Thanks,
    Taragini

  • How to delete the messages from SXMB_MONI which are already cancelled .

    Hi All,
    The messages were earlier in System error(Red flag) state so i cancelled it manually.
    I want to know how to delete the messages from sxmb_moni which are already cancelled manually using ctrl+f8.
    if not possible , then i want to see them in earlier state i.e.., in System error(Red flag).
    can any tell me the procedure of doing it.
    thanks
    Sai.

    Hi AmitSri,
    Thanks for u r reply,
    What is retention period, where can i find this option.
    And i don't have authorizations to sxmb_adm --> configure delete procedure
                                                                             --> Define interfaces for archiving and retention period.
    and to RSXMB_DELETE_MESSAGES in se38 , i don't have authorizations to run
    Is there any way to delete the messages or make them to System error( Red flag) which are manually cancelled.
    Thanks
    Sai.
    Edited by: sai_SHA on Aug 17, 2011 12:29 AM

  • How to delete the messages from sxmb_moni with status cancelled

    Hi ,
    how to delete the messages from sxmb_moni with status cancelled
    Is there any report for this
    Regards
    Suman

    I think just for deleting the jobs you can do this only
    Scheduling Delete Jobs
    To schedule delete jobs, proceed as follows:
           1.      In the Integration Engine -
    > Administration menu, choose Schedule Delete Jobs.
           2.      Select the job(s) to be scheduled.
           3.      Specify the start time and date.
           4.      Specify the period you want to use and choose Schedule.
    For an overview of all jobs, choose Jobs.

  • How to delete the messages from JMS Queue

    Hi,Can anybody help how to delete the messages from the JMS Queue.Thanks in advance.

    You can dequeue the message using a JMS client or delete it using Weblogic Admin Console -
    http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13952/taskhelp/jms_modules/queues/ManageQueues.html
    Regards,
    Anuj

  • How to Read the Image in SQL server

    I want to read the image from SQL server using labview.In our project languages used are JAVA and Labview
    Through java we acquiring the image and write in to SQL Server.
    Through Labview I want to read the image form SQL server and i will do some image processing for my application.
    My problem when I seen the database the images shown like hex decimal value.
    I want to convert the hexadecimal value to image or any other functions is there to directly read the image from SQL server.
    Can anybody help me....

    two options:
    1. save the image data itself (as a blob)
    2. save the image in a file system and save the file name in the DB

Maybe you are looking for

  • IP address error when try to print from GS4

    I have set up ahome network so we can print from our phones or laptops wirelessly (no internet). The phones are Galaxy S4s, the printer is an HP Photosmart Plus B210 series, and the router is a netgear. The router has been reset to factory to erase t

  • Nano 5g and the hold button

    About a week ago I turned the hold button on and couldn't get the hold button to turn off for almost then an hour. Then it just stopped and I haven't had the problem since. For the last three days, I've been having a different problem with the hold b

  • I just downloaded the Adobe XI trial version and when I try to start it I get a message that says the trial is over.

    I downloaded the Trial Version of Adobe Acrobat XI last week, February 20, 2015, using the Adobe Download Assistant. When I try to start the program I get a message that "your trial period has expired"  How do I get the trial to work? Should I uninst

  • Unknown Error Problem

    I was trying to restore album art to my iPod, and during the process of syncing, I get an unknown error message, number -50. I've been having problems with displaying album art, and I'd have to delete the album art in order to restore it. Now, I go t

  • Security Information Request

    I was looking for some information on or a link to information on the security fixes that relate to the various releases of JRE. The reason for the request is that I come from a shop that has as many as 9 different iterations of JRE from 1.31_02 to 1