• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

Unzip txt file by using *.txt?

Hi experts,

I can unzip a txt file by using the code below, however, I have more then 70 txt files that need to done in one procedure, how can I do? please advice. Thank you.

EXEC master..xp_cmdshell 'C:\Progra~1\utility\WinZip\winzip32 -e C:\DATA\FTP_Download\ca_account_sales_org.zip C:\DATA\FTP_Download\ '
0
LIULIHUA
Asked:
LIULIHUA
  • 2
1 Solution
 
Anthony PerkinsCommented:
Perhaps you would consider using DTS instead of xp_cmdshell ?
0
 
LIULIHUAAuthor Commented:
Would you please show me how? thanks.
0
 
rafranciscoCommented:
You can also do it this way:

CREATE TABLE ##Files ( FileName VARCHAR(100))

INSERT INTO ##Files
EXECUTE master.dbo.xp_cmdshell 'dir /b "C:\DATA\FTP_Download\*.zip"'

DECLARE cFiles CURSOR FOR
    SELECT FileName FROM ##Files

DECLARE @FileName VARCHAR(50)
DECLARE @SQL VARCHAR(2000)

OPEN cFiles
FETCH NEXT FROM cFiles INTO @FileName
WHILE @@FETCH_STATUS = 0
BEGIN
   SET @SQL = 'C:\Progra~1\utility\WinZip\winzip32 -e C:\DATA\FTP_Download\' + @FileName + ' C:\DATA\FTP_Download\ '
    EXEC master..xp_cmdshell @SQL

    FETCH NEXT FROM cFiles INTO @FileName
END

CLOSE cFiles
DEALLOCATE cFiles
0
 
LIULIHUAAuthor Commented:
This is big help, can I know how to do this using DTS?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now