

you need to have some files in the source filepath and destination filepath for comparing.

I think that the filepath (C:\Source) which you have specified does not exist. The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.īelow are the sample of MyFiles that I am getting. Run the RECONFIGURE statement to install. Run the RECONFIGURE statement to install.Ĭonfiguration option 'xp_cmdshell' changed from 1 to 1. I tried the codes, it worked but get stucked in the datetime conversion problem as below:Ĭonfiguration option 'show advanced options' changed from 1 to 1. I like to do that so I can compare the attributes of those two files against another XML file that I created/exported after running a SQL query.
XCOPY TO COMPARE FOLDERS CODE
What changes do I need to make to the code so that I would be able to store those files in a directory on my drive. Are those two files stored on a Temp Table or on a drive? In your example , as shown in your pics, the MakeXML stored procedure would return two XML files for the Source and Destination folder. The ‘NewFiles' folder one by one using the DOS xcopy command.Īfter the two stored procedures have been created the code is executed as follows: The output of this is put into a Cursor so that such files are then copied to The second comparison will fetch all the files from Source folder that do.First the comparison would be on the basis of filename having different.The XML documents and make two types of comparison on those. It will fetch all the values from the nodes of both First copy all the files found mismatched on modified date into NEXT FROM INTO '" "' + + '"'ĮXEC xp_cmdshell NEXT FROM INTO CompareXML stored procedure above will first call the ‘MakeXML' sp and get Fetch all the extra files in the source folder SELECT N.value('ModifiedDate','varchar(100)') AS MDATE , Join both the tables retrieved from xml on filename and get all the files having modifieddate mismatch Call the MakeXML sp to return the XML for Source and Destination Folders Make an xml out of separated ModifiedDate,FileName columns and SET the OUTPUT parameterįor our example the stored procedure would return XML for the Source folder ordered
XCOPY TO COMPARE FOLDERS UPDATE
UPDATE SET FileName=SUBSTRING(fullpath,40,LEN(fullpath)) UPDATE SET ModifiedDate=SUBSTRING(fullpath,1,PATINDEX('%M%',fullpath)+1) Separate the modified date from the fullpath txt or can specify the file type you want to compare on use xp_cmdshell stored procedure to run dos commandsĮXECUTE xp_cmdshell all the files that are other than. run dir command on the path specified by ordering on the date modified To update the currently configured value for this feature. To update the currently configured value for advanced options. To allow advanced options to be changed.ĮXEC sp_configure 'show advanced options', 1 INPUT THE FILEPATH FOLDER AND IT WILL RETURN AN XMLĭECLARE TABLE (MyID INT IDENTITY(1,1) PRIMARY KEY,FullPath VARCHAR(2000),ModifiedDate datetime, FileName VARCHAR(100)) Shown below are the set of files with their modified date in the Source folder: Problem is to identify differences between the files in the Source and Destinationįolders and copy all the modified or new files from the Source Folder to the folder Of file) in the Source folder and the Destination folder contains two files.

