How to move files along with folder

  • I have a Main folder contains all Subfolders with the excel files ,which i need to process

    say for eg :

    MainFolder name is "Testing"

    SubFolders inside the MainFolder are

    Testing1 (contains 3 excelfiles)

    Testing2 (contains 3 excelfiles)

    Testing3 (contains 3 excelfiles)

    Testing4 (contains 3 excelfiles)

    Now my requirement is , i need to process file by file and move the file into the Processed or Error folder

    along with subfolder

    For eg : Testing1 folder contains 2 invalid files and 1 valid file , then

    2 Invalid files should go to Error folder along with the sub folder and 1 valid file should go processed folder along with subfolder

    Finally the folders should contain files as fallows

    Error Folder -> Testing1 folder -> 2 excelfiles

    Processed Folder -> Testing1 folder -> 1 excel file

    Thanks in Advance

  • DECLARE @SourceFileName varchar(255)

    Declare @Destination varchar(255)

    DECLARE @ExecCmd VARCHAR(255)

    SET @SourceFileName = '"\LoadFile.txt"'

    set @Destination = '"\LoadFile.txt"'

    SET @ExecCmd = 'move ' + @SourceFileName +' '+@Destination

    EXEC master.dbo.xp_cmdshell @ExecCmd

    make sure your xp_cmdshell command is enabled in your sql server. If it is not enabled run the following command:

    RECONFIGURE

    EXEC sp_configure 'xp_cmdshell', 1

    RECONFIGURE

  • You say 'thanks in advance', but all you've done is told us what you are trying to do, without asking for anything. Which part, specifically, would you like help with?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply