You are not logged in.

#1 28 Nov 2007 02:38

zammalabe
Member
From: Estonia
Registered: 05 Jun 2007
Posts: 27

% character

is it possible to use % sign as regular text within loops  (variable parameter contains the % sign as regular text)? for example, if filename/path contains % within its name, how to use those filenames/paths within loops?

Offline

#2 28 Nov 2007 19:19

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: % character

In general you can use either %% or %%%

See also the section Advanced usage : CALLing internal commands
on this page http://ss64.com/nt/call.html

for filenames it may be easier to just use the 8.3 short name (%~s1)

Offline

#3 30 Nov 2007 00:44

zammalabe
Member
From: Estonia
Registered: 05 Jun 2007
Posts: 27

Re: % character

thanks simon smile

Simon Sheppard wrote:

In general you can use either %% or %%%

... but seems that %%% wont't help me or i can't implement it sad

Simon Sheppard wrote:

for filenames it may be easier to just use the 8.3 short name (%~s1)

this method cuts down the file name, but i need the whole file name ...

to be precise, the code where filenames may contain the "%" sign in their name i cant make work is:

echo on
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

::[ABOUT]
::Unattended Batch Installer
path=%path%;C:\Programs.s;c:\Programs.s\WinRar

::[GLOBALS]
set initial=1\soft
set TempFolderName=~soft~
set ajutine=C:\Temp

::[SOURCEFILES]
for %%i in (C D E F G H I J) do if exist %%i:\Nlited.OS set SourceDisk=%%i
set OSS=wxpsp2
md %ajutine%\%TempFolderName%

::[MAINLOOP]
set Folder1=
set File1=
cd /d %SourceDisk%:\%OSS%\%initial%
set SourcePath=%CD%
pushd %SourcePath%
for %%a in ("*.rar") do (call :unpacker "%%a" & pause)
cd /d %ajutine%\
rd /s /q %TempFolderName%
goto :eof

REM=============UNPACKER=============
:unpacker
set File1=%~1
@echo %file1%
pause
set Folder1=%~n1
title Installing the package of: %File1%
call :CurrDateSub&call :CurrTimeSub
copy /b /v /y ^"%File1%" "%ajutine%\%TempFolderName%"
cd /d %ajutine%\%TempFolderName%
attrib -r -a -s -h "%File1%"
rar.exe x -ad -o+ "%File1%"
del /f /q "%File1%"
IF exist "%Folder1%\set.ini" (call :installer) ELSE cd ..
rd /s /q "%Folder1%"
popd
pause
goto :eof

REM=============INSTALLER=============
:installer
cd "%Folder1%"

the code will continue, but the problems appear in this part
some pauses and echoes are just for feedback ...

when the batch tries to copy the file with %sign in it name

copy /b /v /y ^"%File1%" "%ajutine%\%TempFolderName%"

, it gives an error, that such file don't exist, actually the %sign is removed/ignored in this line:

for %%a in ("*.rar") do (call :unpacker "%%a" & pause)

...as %%a value is passed to next loop ... where the problem appear

Last edited by zammalabe (01 Dec 2007 04:43)

Offline

Board footer

Powered by