Posted - 07/10/2013 : 11:28:48
| below I have a trigger that works however if there are 3 files in the location I am moving files from it moves all 3 and I only want it to move the oldest file of the 3. Then when the trigger is activated again I want it to again select only the oldest of the files in the said folder. Any help is much appreciated.
TRANS FOR INSERT, UPDATE AS
update STATION set station.BinQuantity = 1
INNER JoiN INSERTED
STATION ON TRANS.ITEM = STATION.ITEM
INSERTED.TYPEDESCRIPTION = 'ISSUE' AND INSERTED.ITem LIKE 'RECEIVE%'
DECLARE @file varchar(80), @cmd varchar(500);
CREATE TABLE #temp(line varchar(100));
EXEC sys.xp_cmdshell 'dir /B C:\OLD';
SELECT TOP 1 @file=line
WHERE line IS NOT NULL
ORDER BY line;
DROP TABLE #temp;
SET @cmd='MOVE /Y C:\OLD\'+@file+' C:\NEW\receive.csv'
EXEC sys.xp_cmdshell @cmd;