December 11, 2015 at 12:58 pm
Hello,
Ina Stored Procedure I am using the move command to transport files. Is there a way to check if the file already exists and if it does rename the new file with a version number?
Here is my code:
SET @cmd = 'MOVE /Y ' + @Folder_Dir + @FilesInDir + ' ' + @Error_Dir
EXEC sys.xp_cmdshell @cmd;
PRINT @cmd
Is there a cmd or simple way to check if the file is already there and if it is rename the new file to say filenamev2?
December 11, 2015 at 10:08 pm
https://technet.microsoft.com/en-us/library/bb490920.aspx?f=255&MSPPError=-2147217396, 3rd example
if [not] exist FileName command [else expression]
and
https://technet.microsoft.com/en-us/library/bb490987.aspx, 2nd example:
ren [Drive:][Path] filename1 filename2
December 12, 2015 at 7:54 pm
Meatloaf (12/11/2015)
Hello,Ina Stored Procedure I am using the move command to transport files. Is there a way to check if the file already exists and if it does rename the new file with a version number?
Here is my code:
SET @cmd = 'MOVE /Y ' + @Folder_Dir + @FilesInDir + ' ' + @Error_Dir
EXEC sys.xp_cmdshell @cmd;
PRINT @cmd
Is there a cmd or simple way to check if the file is already there and if it is rename the new file to say filenamev2?
No. You'll need to read the file names from both directories, make the comparison, and change the move command to move just one file at a time so that the destination file name can be changed.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 12, 2015 at 7:56 pm
p.s. I recommend that you use ROBOCOPY (comes with DOS/Windows) instead. It has auto restart if a file fails part way through, logging, and a whole bunch of other features that simply aren't available in the older DOS file commands.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply