• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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