Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2007-11-14 : 12:47:33
|
How can create a 0 byte file from T-SQL (using xp_cmdshell). |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2007-11-14 : 13:05:38
|
I can't get it to create a 0-byte file, but I can create an empty one via:DECLARE @CMD varchar(55)SET @CMD = 'ECHO. > X:\SomePath\Foo.txt'exec master..xp_cmdshell @CMD |
 |
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2007-11-14 : 13:12:16
|
This creates an 1KB file (Though it's empty I need an 0 byte file) |
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2007-11-14 : 13:26:26
|
I don't think you're going to be able to do it with dos commands... |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-11-14 : 14:40:23
|
[code]-- Create Empty fileexec master.dbo.xp_cmdshell 'copy nul: D:\MyEmptyFile.txt'-- Do directory of Empty fileexec master.dbo.xp_cmdshell 'dir D:\MyEmptyFile.txt'-- Delete Empty fileexec master.dbo.xp_cmdshell 'del D:\MyEmptyFile.txt /f /q'Results:output---------------------------------------------------------------------- 1 file(s) copied.NULL(2 row(s) affected)output---------------------------------------------------------------------- Volume in drive D is LOCAL_D Volume Serial Number is C467-4C9ZNULL Directory of D:NULL11/14/2007 02:38p 0 MyEmptyFile.txt 1 File(s) 0 bytes 0 Dir(s) 7,185,264,640 bytes freeNULL(9 row(s) affected)output----------------------------------------------------------------------NULL(1 row(s) affected)[/code]CODO ERGO SUM |
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2007-11-14 : 14:44:14
|
quote: Originally posted by Michael Valentine Jones [code]-- Create Empty fileexec master.dbo.xp_cmdshell 'copy nul: D:\MyEmptyFile.txt'
Very nice. Gotta remember that one... |
 |
|
|
|
|