Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a text file with the following values

datasource=c:\temp\datasource

Which I am then attempting to read from a batch file and populating a for loop.

for /f "tokens=1,2 delims==" %%b in (config.txt) do ( 
if %%b==datasource set datasource=%%c 
) 

for %%a in (%datasource%\*.*) do if "%%~xa" == "" "C:\Program Files\7-Zip\7za.exe" a -tzip -mx9 "%%a.zip" "%%a"

The error I get is

System error:
Incorrect function.

Press any key to continue . . .

Now if I replace %datasource%\*.* with c:\temp\datasource\*.* it works just fine.

What am I doing wrong?

EDIT0

The results of removing @echo off

REM @echo off

setlocal enabledelayedexpansion

for /F "tokens=1,2 delims==" %b in (config.txt) do (
if %b == datasource set datasource =%c
)

D:\sftp\winscp438>(
if datasource == datasource set datasource=c:\temp\datasource

)

for %a in (c:\temp\datasource\*.*) do if "%~xa
" == "" "C:\Program Files\7-Zip\7za.exe" a -tzip -mx9 "%a.zip" "%a"

if "" == "" "C:\Program Files\7-Zip\7za.exe" a -tzip -mx9 "c:\temp\datasource\sample.zip" "c:\temp\datasource"

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Error: c:\temp\datasource\sample.zip is not supported archive


System error:
Incorrect function.
share|improve this question
    
Do you mean you have set datasource=c:\temp\datasource? –  martineau Aug 28 '12 at 22:20
    
@martineau - No. The datasource is simply a line in the text file –  PeanutsMonkey Aug 28 '12 at 22:29
    
Do you have @echo off in your batch file? Take it out (comment it out) and see (and tell us) what it tells you. –  Scott Aug 28 '12 at 22:33
    
Sorry, thought it was part of the batch file. –  martineau Aug 28 '12 at 22:40
    
@Scott - Yes I do. Have posted the results above in my post. –  PeanutsMonkey Aug 28 '12 at 23:02

3 Answers 3

up vote 0 down vote accepted

The error you are seeing is returned by 7Zip when the archive specified is invalid. This can mean either you are specifying the wrong archive type, the target file is a corrupt archive, or it is not an archive (effectively the same as being a corrupt archive).

I suspect what happened was that while you were crafting your batch file, you had initially left out the -tzip switch and so created .7z files with .zip extensions. Thus, when you subsequently added the switch, 7Zip looks at them and sees 7Zip files, but you are specifying zip, and so it throws the error.

Try setting things back to the way they were above, then delete c:\temp\datasource\*.zip and run the batch file again.

Also, assuming your directory names are stand-ins, then you should wrap your variables in quotes to avoid problems with spaces:

for %%a in ("%datasource%\*.*") do if …
share|improve this answer
    
I believe you mean "delete c:\temp\datasource\*.zip". –  Scott Aug 29 '12 at 18:41
    
Yes; actually I meant to change that last night but forgot. Thanks. –  Synetech Aug 29 '12 at 18:51
    
Good catch on the quotes. It made me think of the semi-obvious corollary: the datasource name must not contain any "=" characters, as datasource=c:\temp\my=data won't be parsed correctly. –  Scott Aug 29 '12 at 20:00
    
Right because the equal sign is indeed a valid character for file and folder names. So many little details and catches to look out for. And people wonder why there are so many bugs in software… –  Synetech Aug 29 '12 at 20:18

try using the set command

Set command description

share|improve this answer
    
I already have in the batch file. Why would I need to set it in the text file that holds the configuration values? –  PeanutsMonkey Aug 28 '12 at 22:29

The only way I could get it to work was to move the path c:\temp\datasource\*.* to the config.txt file so that the only parameter within the parenthesis was %datasource%. Not sure whether this is normal.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.