While deleting files using xp_cmdshell, does the date column look for file creation date or last modified date?

  • 1
    That depends on what you're executing in the shell. Post your code. – alroc Jan 28 '18 at 16:28
  • 2
    xp_cmdshell doesn't take any kind of date argument, it just passes your command to the underlying Windows cmd. So what command are you passing? Why are you doing this kind of thing from SQL Server through xp_cmdshell, instead of maintaining your file system independently of SQL Server altogether (e.g. PowerShell)? – Aaron Bertrand Jan 28 '18 at 18:18

If you are thinking about using the FORFILES command with the /D parameter, this uses the last modified date. Type FORFILES /? to get more info about this command. See also https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

Not the answer you're looking for? Browse other questions tagged or ask your own question.