James Khan
James Khan

Reputation: 841

Assistance with coding change in Windows batch script?

I have a batch script which unzip and renames each file.
Unfortunately I now need to keep the filename of the zip file it came from.

Example Jazz1.zip now unzips and the outcoming text file becomes 1.Jazz1.zip.txt.
So I want %%F to become %%F - 4- characters.

Unfortunately I want it to be Jazz1.txt.

::Setup the stage...
SETLOCAL ENABLEDELAYEDEXPANSION
SET folder=C:\P\DataSource2_W
SET count=1

::Action
CD "%folder%"
FOR %%F IN ("*.zip") DO (

 "C:\Program Files (x86)\WinZip\wzunzip" %%F
  MOVE *.txt "C:\P\DataSource2_W\TextFiles\!count!%%F.txt"
  SET /a count=!count!+1
)
ENDLOCAL

Upvotes: 0

Views: 96

Answers (1)

dbenham
dbenham

Reputation: 130809

I do not understand what you are trying to do with the COUNT variable, nor do I understand how you are handling a ZIP file with multiple .TXT files.

But I do understand that you want the base name of each ZIP file, (name without the extension). That is easy - simply use the ~n modifier (type HELP FOR from the command prompt for more info).

So if %%F = Jazz1.zip, then %%~nF yields Jazz1

Upvotes: 2

Related Questions