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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Creating 0 byte file

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
Go to Top of Page

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)
Go to Top of Page

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...

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-11-14 : 14:40:23
[code]
-- Create Empty file
exec master.dbo.xp_cmdshell 'copy nul: D:\MyEmptyFile.txt'

-- Do directory of Empty file
exec master.dbo.xp_cmdshell 'dir D:\MyEmptyFile.txt'

-- Delete Empty file
exec 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-4C9Z
NULL
Directory of D:NULL
11/14/2007 02:38p 0 MyEmptyFile.txt
1 File(s) 0 bytes
0 Dir(s) 7,185,264,640 bytes free
NULL

(9 row(s) affected)

output
----------------------------------------------------------------------
NULL

(1 row(s) affected)



[/code]

CODO ERGO SUM
Go to Top of Page

Haywood
Posting Yak Master

221 Posts

Posted - 2007-11-14 : 14:44:14
quote:
Originally posted by Michael Valentine Jones

[code]
-- Create Empty file
exec master.dbo.xp_cmdshell 'copy nul: D:\MyEmptyFile.txt'



Very nice. Gotta remember that one...
Go to Top of Page
   

- Advertisement -