2017-10-10 2 views
0

J'ai utilisé une boucle For/f pour lire les valeurs stockées dans un fichier, (le contenu se trouve en bas de mon article d'origine) et stocker les paramètres dans les variables qui sont générés à la volée en utilisant count + 1, de cette façon le nombre de paramètres utilisables est ouvert (comme l'utilisation prévue est de monter des partages pour conduire des lettres, il peut y avoir un nombre arbitraire de disques et donc de paramètres).Besoin d'aide pour utiliser "if" en batch avec des variables et des chaînes

Tous les paramètres utilisés doivent correspondre et être connus du script, et chaque paramètre a un paramètre associé. Un exemple de ceci est le premier paramètre que j'ai défini dans mon fichier était (Mode) et son réglage était (LAN). La façon dont les boucles For/f (deux d'entre elles) ont été écrites ainsi que la façon dont le fichier de configuration a été écrit tous les paramètres utilisés seraient assignés à un nombre (var #) en utilisant var! Count! à la volée, et le réglage associé serait assigné à (avar #). Cependant, comme les paramètres peuvent être listés dans n'importe quel ordre, la seule condition étant que le paramètre associé soit sur la même ligne et après le symbole du délimiteur, le numéro attaché à var/avar sert seulement à s'assurer que tout est stocké dans un variable unique.

je tente alors d'utiliser « si » pour correspondre au paramètre stocké dans tout var # la boucle travaille, à des valeurs connues utiles au projet, par exemple

var1 = Mode avar1=LAN  as set by the For /f loop 

if var!count!==Mode (SET Mode=avar!count!) 

doit correspondre, espérons que var1 a le paramètre Mode stocké à l'intérieur, de sorte que la variable Mode doit être définie sur tout ce qui est stocké dans avar1 (Lan) dans ce cas (var1 va avec avar1, var2 va avec avar2, etc.)

Le problème est que le si les déclarations n'évaluent jamais à vrai. Un exemple de code simplifié suit, et je même à des fins de test, régler manuellement var1 près du sommet, même si cela est censé être fait par la boucle Pour/F et il n'a toujours pas évalué à true

setlocal EnableDelayedExpansion 
@echo off 
SET count=1 
FOR /f "eol=; skip=18 tokens=2 delims=#@" %%x in (C:\OConf.ini) DO (
SET var!count!=%%x 
SET /a count=!count!+1 
echo value 1 is %%x 
) 

SET count=1 
FOR /f "eol=; skip=18 tokens=2 [email protected]" %%x in (C:\OConf.ini) DO (
SET avar!count!=%%x 
SET /a count=!count!+1 
echo value 2 is %%x 
) 


SET var1 == Mode 

:SetCounters 
SET /a count=1 
:SetVars 
echo test var!count! 

IF NOT DEFINED var!count! (GOTO CleanOne) 
if var!count! == Mode (Echo If this is seen then the "if" evaluated as true) 
Echo The value of var1 equals (%var1%) 
goto EOF 

:CleanOne 
Echo If you see this then var!count! is null 

:EOF 
Echo EOF2 

Pour la personne qui a mentionné le bit sur EOF, je pensais que cela fonctionnait comme fin de fonction sans avoir besoin d'une balise, mais au moins une fois je l'ai couru, ça n'a pas semblé fonctionner (même si l'instruction IF a échoué de façon désagréable (est arrivé à quelques reprises))

======================================= ====================

Plus d'original p compliqué ci-dessous, selon quelques conseils, j'ai simplifié et clarifié ma question, qui a été révisée ci-dessus.

============================================== =============

Je crée une solution Windows 10 PE via winbuilder, en fin de compte je l'espère pour être utilisé à partir d'au moins 3 méthodes (directement à partir d'un lecteur flash/DVD, multi-boot via un utilitaire appelé easy2boot, et PXE démarré à partir du réseau). Cependant, une grande partie de la fonctionnalité que j'ai implémentée requiert des fichiers supplémentaires accessibles à la lettre Y :, mais selon la façon dont vous avez démarré cela peut vouloir dire monter un fichier image, monter un partage réseau ou simplement lire le lecteur flash ou le DVD que vous avez démarré de. En tant que tel, j'écris un script qui s'exécute avant que le shell ne se charge au démarrage. La première chose à faire est de vérifier la racine de chaque disque pour un fichier de configuration. S'il est disponible, il peut aller en ville, s'il n'est pas disponible, il invite l'utilisateur à répondre à quelques questions et part de là.J'ai écrit ce que j'appellerai des «scripts simples» depuis des années, des types qui sont statiques et linéaires dans leur fonctionnement, c'est ma première vraie tentative de ce que je vais appeler un «script dynamique» qui a des sous-programmes et des boucles modulaires et tous les chemins seront relatifs et/ou l'utilisateur invité mais pas codé en dur.

Le script principal que j'ai écrit pour sa part fonctionne bien pour lui-même et pour le sous-programme de LAN maintenant terminé et les échos le texte de l'espace réservé bien pour les sous-programmes E2B et Flash.

Je travaille actuellement sur la sous-routine qui vérifie un fichier de configuration et s'exécute avec cette entrée d'utilisateur. Je pensais que tout allait bien se passer dans l'espace de script en oubliant de tester pendant un moment ...

... Lorsque je fais un test, je trouve que les instructions "IF" que j'utilise n'évaluent jamais à vrai, même si je mets manuellement la variable et je sais que c'est une correspondance. J'ai essayé toutes les permutations auxquelles je peux penser avec des guillemets, sans, avec des points d'exclamation, des espaces, pas d'espace et des possibilités de placement différentes ... Google et googlé et un article que j'ai trouvé ici semblaient avoir fonctionné mais rien essayé de cela a fonctionné du tout, mais cela m'a inspiré de demander ici! Ce qui suit est codé en dur pour la simplicité de développement pour rechercher le fichier de configuration à la racine de mon lecteur, le script maître que je prévois de déposer dans a une boucle "si existe" qui parcourt toutes les lettres de lecteur pour trouver sur n'importe quel lecteur. Aussi, j'ai commenté sur ce script non seulement expliquer ce que fait quoi, mais aussi où j'ai des problèmes. J'ai également commenté quelques choses en double qui sont le résultat de mon expérimentation pour que cela fonctionne. Le script tel qu'il est actuellement lira les valeurs prévues et les affectera à des variables incrémentées et les répercutera pour montrer son fonctionnement, mais échouera lorsqu'il essaiera de déterminer le contenu lu et de l'assigner aux variables appropriées à utiliser dans faire des choses se produire

setlocal EnableDelayedExpansion 
@echo off 
::sets the primary counter for the "For" Loop 
SET count=1 
:: FOR loop to set varibles for the descriptive name of the setting to be 
adjusted for use in 
:: determining what the setting value is to adjust 
FOR /f "eol=; skip=18 tokens=2 delims=#@" %%x in (C:\OConf.ini) DO (
SET var!count!=%%x 
SET /a count=!count!+1 
echo value 1 is %%x 
) 
::sets the primary counter for the "For" Loop 
SET count=1 
::FOR loop to determine the setting values that go with each descriptive Name 
FOR /f "eol=; skip=18 tokens=2 [email protected]" %%x in (C:\OConf.ini) DO (
SET avar!count!=%%x 
SET /a count=!count!+1 
echo value 2 is %%x 
) 

:MyLabel 

::diagnostic code to reference what value is being stored 
echo this is var1: %var1% 
echo this is avar1: %avar1% 
echo this is var2: %var2% 
echo this is avar2: %avar2% 
echo this is var3: %var3% 
echo this is avar3: %avar3% 
echo this is var4: %var4% 
echo this is avar4: %avar4% 
echo this is var5: %var5% 
echo this is avar5: %avar5% 
echo this is var6: %var6% 
echo this is avar6: %avar6% 
echo this is var7: %var7% 
echo this is avar7: %avar7% 
echo this is var8: %var8% 
echo this is avar8: %avar8% 
echo this is var9: %var9% 
echo this is avar9: %avar9% 
echo this is var10: %var10% 
echo this is avar10: %avar10% 
echo this is var11: %var11% 
echo this is avar11: %avar11% 
echo this is var12: %var12% 
echo this is avar12: %avar12% 

::echo this is avar1: %avar1% 
::echo this is avar2: %avar2% 
::echo this is avar3: %avar3% 
::echo this is avar4: %avar4% 
::echo this is avar5: %avar5% 
::echo this is avar6: %avar6% 
::echo this is avar7: %avar7% 
::echo this is avar8: %avar8% 
::echo this is avar9: %avar9% 
::echo this is avar10: %avar10% 
::echo this is avar11: %avar11% 
::echo this is avar12: %avar12% 

::in my sample script I am testing against var/avar is known to be null this is test code 
echo this is avar13: %avar13% test 
::this code is to show me what part of the script has or has not executed 
echo this is not final 



:SetCounters 
::Set primary counter for script advancement 
SET /a count=1 
::Set drive letter counter so it can be compared to the share counter 
SET /a D=1  
::Set network share counter so it can be compared to the drive letter counter 
SET /a S=1  
:SetVars 
::Subrotine to fill in variables for use in the up coming action subrutines 
::Diagnostic line added when things were not working right 
echo test var!count! D is %D% S is %S% 

::escape subrutine so when all values have been filled in, this loop ends and goes to use 
IF NOT DEFINED var!count! (GOTO CleanOne) 

:: This is the heavy lifting of this subrutine (also currently non functional for unknown reasons) 
:: If bank compares the value of var# (where # is a counter set number) to known valid values, when 
:: the valid value is found to match, its associated setting held in avar# is to the batch varible 
:: of the same name. Commented out code is either non functional or untest but a new approach concocted 
:: before testing, but the need to return to it may come up so not removed. denoted as not part of 
:: this description by adding a preceeding astrik 
:: ======================================================================================== 

:: Mode is the first test & despite everything I have tried will not evaluate to true 
:: tried multiple iterations of including quotes (or not), exclamations and percents symbols 
:: around the varibles different ways "var!count!" var!count! %var%!count! 
%var!count!% !var!!count! !var!count!! 
:: and a bunch of others, similar iterations around mode, tried spaces and no spaces next to the equal symbols 
:: also tried reversing the order of the comparison... *******HELP******* 
::*if "%var%!count!" == "Mode" (Set Mode=avar2 echo test mode %Mode%) 
:: Next line is bastardized to simply see when the expression evaluates to true 
:: if Mode == !var!!count! (Echo Equal) 
:: next commented out command is supposed to remove quotes if present to prevent issues, will return to this 
:: concept once the issue with the IF statements is dealt with 
::*SET Mode=%avar!count!:"=% 
:: also a diagnostic command 
::*echo test mode %Mode% 



::======================================================= 
:: lines between here and the next divider for me have been temporarily cut to another file to reduce clutter 
:: and save my sanity while I takle the problem. pasted back to demonstraight intended functionality. 

:: Mode has 3 valid options currently, Flash/DVD, LAN, E2B and will be used to either mount a image file on a E2B 
:: drive to a drive letter, or to mount (possibly multiple) network shares to drive letters 
if var!count!==Mode (SET Mode=avar!count!) 
::if var!count!==Mode (SET Mode=%avar!count!:"=%) 

:: Perf is short for performance and is to determine if the install driver packs subroutine should run to increase performance 
:: and or recognize otherwise unknown devices, declining this uses only baked in drivers. Valid options are Yes/No 
if var!count!==Perf (Set Perf=avar!count!) 
::if var!count!==Perf (SET Perf=%avar!count!:"=%) 

:: ImgPth is for the image path to be mounted to the Y:, currently it is only intended that 1 image be mounted however 
:: as I write this I realize the way I am approaching mounting network shares could allow multiple images to be added also 
if var!count!==ImgPth (Set ImgPth=avar!count!) 
::if var!count!==ImgPth (SET ImgPth=%avar!count!:"=%) 

:: NumDrv is supposed to be how many network shares were to be mounted so the script could allocate enough varibles 
:: I have sense adopted a new approach that can auto-detect and just run, haven't removed yet 
if var!count!==NumDrv (Set NumDrv=avar!count!) 
::if var!count!==NumDrv (SET NumDrv=%avar!count!:"=%) 

:: Server is used to name the server that has the network share on it that will get mounted to a drive letter 
:: the tools used only support one server connection via one user name, so this can only be set once. 
:: eg \\server01\something\share would translate to server01 (no need for slashes) 
if var!count!==Server (Set Server=avar!count!) 
::if var!count!==Server (SET Server=%avar!count!:"=%) 

:: Usr is the user name to authenticate with the server to access the network share 
:: the tools used only support one server connection via one user name, so this can only be set once. 
if var!count!==Usr (Set Usr=avar!count!) 
::if var!count!==Usr (SET Usr=%avar!count!:"=%) 

::Pass is the password to use in authenticating with the server 
:: the tools used only support one server connection via one user name, so this can only be set once. 
if var!count!==Pass (Set Pass=avar!count!) 
::if var!count!==Pass (SET Pass=%avar!count!:"=%) 

::DrvLtr denotes what drive letter you want the network share mounted to. X: will already be in use by the system 
:: if using on a computer with windows installed on local HDD then C: will be in use. If newer windows with recovery 
:: partitions and or otherwise multiple drives/partitions D: E: will also likely be in use. Y: is a special case and 
:: ultimatly the point of this entire script. Core files to boot and opperate are loaded to the X: ram disk, however 
:: to save RAM and increase compatibility additional functionality that requires additional files not stored in the 
:: ramdisk need to be mounted to Y: and Y: is reserved for this use only. So do not use C: D: E: X: (Y: unless its for 
:: the specified files) 
if var!count!==DrvLtr ( 
Set DrvLtr!DL!=avar!count! 
::Set DrvLtr!DL!=%avar!count!:"=% 
::Next bit was intended to be a diagnostic message, alas the test never got that far 
Echo DrvLtr Subroutine has run for the !DL! time and stored %DrvLtr%!DL! for use 
:: the counter being modified below allows for it to be determined how many times this subroutine has run 
:: by the time this loop exits it should match the number of times the Share routine has run, if it doesn't 
:: then there is an error, but by taking the smaller number and running the mount share command only the 
:: lessar times it can be assured each share has a drive letter and vice versa 
SET /a DL=!DL!+1 
) 
:: path to the network Share, multiple of these can be mounted to different drive letters 
:: eg \\server01\something\share would translate to something\share, or if the share isnt in a sub folder 
:: eg \\server01\share then it would translate to just share (slashes only used if more then one folder deep) 
if var!count!==Share ( 
Set Share!SH!=avar!count! 
::Set DrvLtr!SH!=%avar!count!:"=% 
Echo DrvLtr Subrutine has run for the !SH! time and stored %DrvLtr%!SH! for use 
:: the counter being modified below allows for it to be determined how many times this subroutine has run 
:: by the time this loop exits it should match the number of times the Share routine has run, if it doesn't 
:: then there is an error, but by taking the smaller number and running the mount share command only the 
:: lessar times it can be assured each share has a drive letter and vice versa 
SET /a SH=!SH!+1 
) 
:: advances the main counter so the next pass through the loop doesn't use the same variable and thus the same information 
SET /a count=!count!+1 
:: its commented out for troubleshooting but this goto is to repeat the loop 
::goto :SetVars 
pause 
:: the above if statements currently are nonfunctional, the below is my first draft at takling the idea of mounting multiple network shares 
:: before realizing the approach had some limitations in how drive letters and their respective shares could be listed in the config file 
:: originally intended that the config file would list either the letter then the share, next letter next share, or possibly share then letter 
:: this code was then tweaked so the config file could accept letter, share, share, letter, letter, share; however having more then two letters 
:: and or shares in sequence would conceptially (I never tested this code) break the code, and a bathroom break brainstorm would clue me into 
:: much simpler code that shouldnt care how the drive letters and shares are listed as long as there are equal numbers of them, and if theres not 
:: a still useable fail can be acheved by using the lower number of how many shares listed vs drive letters 

REM attempting subroutine rewrite to be completly agnostic to drive verses share ordering, commented out subroutine in case 
REM I fail and or I need to use parts of this 
REM #(if sh) commented out as more versitile and similar functionality provided by adding another counter advance near the end 
REM #this should allow the drive letters or shares to be listed back to back and still be set as long as its still grouped to 
REM #one side or the other with its other value (S= share D= Drive: DSDSDS was the original plan, DSSDDS or SDDSSD would be prevented 
REM #by this method but would work with the counter advance) 
::if var!count!==DrvLtr (              
REM Checking for drive letter option 
::if SH==0 (   REM checking if share has already been set this plus next option prevents a required order of things, though the options must be set together 
::Set DrvLtr=avar!count!      REM Sets the Drive Letter value 
::SET /a count=!count!+1      REM If share hasnt been set, advances the counter so the share can be set 
::if var!count!==Share (Set Share=avar!count!  REM sets the share 
::Set /p DL=1    REM notates that the share has been set so the next subroutine wont muck things up trying to do the same thing 
::echo DrvLtr Subrutine has run varibles are %DrvLtr% and %Share% REM Diagnostic message to know if this subrutine ran and if so did it set correctly 
::SET /a count=!count!+1  REM advances the counter so presumably the share subrutine wont run as it was set here 
::) 
::else (Echo Share set errored) 
::) 
:CleanOne 

:: makes sure the number of drive letters requested matches the number of shares being mounted or if not uses the lesser number 
Set /a Dnum=!DL! 
set /a Snum=!SH! 
If %Dnum% LEQ %Snum% set /a RC=%Dnum% 
If %Snum% LEQ %Dnum% set /a RC=%Snum% 
goto :CleanTwo 

:CleanTwo 
REM to modify later, currently echoing to test current script operation 
:: this is when I decided to test and discovered the broken IF statements 
:: this subroutine was conceptualized and removing all quotes that maybe stored in variables, however before writing something to do that 
:: I found sample code that could do that on the fly and wrote it into the if statements, sense being commented out as I tackle why the IF's are broken 
Echo Mode equals %Mode% 
Echo Perf equals %Perf% 
Echo NumDrv equals %NumDrv% 
Echo Server equals %Server% 
Echo Usr equals %Usr% 
Echo Pass equals %Pass% 
Echo DrvLtr equals %DrvLtr% 
Echo Share equals %Share% 
Echo DrvLtr2 equals %DrvLtr2% 
Echo Share2 equals %Share2% 
Echo DrvLtr3 equals %DrvLtr3% 
Echo Share3 equals %Share3% 

:: after making sure nothing is muddled with quotes, and maybe slashes, and likely inserting some code above the SetVars rutine to set all to either upper/lower 
:: case to prevent issue, the assigned variables will be used. 

:: Flash/dvd will simply ask for the performance option and look for a DriverPacks and install them 
:: if performance mode is desired. 

:: E2B, is for use with Easy2Boot using a .imgptn file which gets mapped to the MBR of the flash drive (it's a compatibility hack for uefi) 
:: easy2boot supports other image files but the functionality of automatically unmounting, and remapping to a drive letter are automatically done with baked in options, 
:: plus access to the E2B drive proper is never lost, with .imgptn being mapped to the drive via the MBR all access to the main drive is lost until you run a script 
:: provided the developer to restore the MBR to its original state. E2B mode in this script is intended to call that script (well a bastardized version that doesnt need 
:: user input, via loops and auto detection (upcoming, my previous version I tweaked for my PE3 build years ago, was hard coded for set options that were true about 90% time, 
:: everything about this project as opposed to my old project is to be modular, relative, and dynamic so hard coding things esp things that dont work all the time are an antithesis) 
:: Once the script is run to restore the original MBR and primary drive access is restored, the image "path\file" stored in ImgPth will be mounted to the Y: using imdisk. 

:: Lan is intended for PXE boot situations and will mount a network share that contains the files needed for Y: to that drive letter, and additionally any extra shares indicated 

:: performance mode will then run or not as specified, followed by starting the shell 




:MyLabel 
:: Original placment of this diagnostic readout, some iterations of the broken IF statements prevented the script from completing 
:: and this was never seen, and in takling this problem I needed to see if these were set so copied above 

echo this is var1: %var1% 
echo this is avar1: %avar1% 
echo this is var2: %var2% 
echo this is avar2: %avar2% 
echo this is var3: %var3% 
echo this is avar3: %avar3% 
echo this is var4: %var4% 
echo this is avar4: %avar4% 
echo this is var5: %var5% 
echo this is avar5: %avar5% 
echo this is var6: %var6% 
echo this is avar6: %avar6% 
echo this is var7: %var7% 
echo this is avar7: %avar7% 
echo this is var8: %var8% 
echo this is avar8: %avar8% 
echo this is var9: %var9% 
echo this is avar9: %avar9% 
echo this is var10: %var10% 
echo this is avar10: %avar10% 
echo this is var11: %var11% 
echo this is avar11: %avar11% 
echo this is var12: %var12% 
echo this is avar12: %avar12% 

::echo this is avar1: %avar1% 
::echo this is avar2: %avar2% 
::echo this is avar3: %avar3% 
::echo this is avar4: %avar4% 
::echo this is avar5: %avar5% 
::echo this is avar6: %avar6% 
::echo this is avar7: %avar7% 
::echo this is avar8: %avar8% 
::echo this is avar9: %avar9% 
::echo this is avar10: %avar10% 
::echo this is avar11: %avar11% 
::echo this is avar12: %avar12% 

echo this is avar13: %avar13% test 
echo this is not final 
goto test2 

:Final 
Echo this is final 

:EOF 

echo done 




pause 
:: a command I refrenced, from something I used a while back 

::SET count=1 
::FOR /F "tokens=* USEBACKQ" %%F IN (`Net User %Username%`) DO (
:: SET var!count!=%%F 
:: SET /a count=!count!+1 
:: SET Shell=Chrome 
) 





::======================================================== 
:: Also these are diagnostic commands and subroutines that may share names with some of the above that was 
:: temporarily cut out as I takle the problem. 
:: Echo %var1% is still var1 right 
:: goto EOF 

:: :CleanOne 
:: Echo CleanOne 13 

:: :EOF 
:: Echo EOF2 


:: commented these out 

également pour référence, le fichier de configuration d'exemple que j'ai testé contre suit:

//Mode Declares how the system should mount additional required files, based on how the system was booted 
// 
//Performance mode Loads drivers either from the Y: or from the E2B flash drive, depending on Mode. 
//Performance mode may take plus or minus 5 minutes to fully load, and installs all relevant drivers found in the 
//DriverPacks folder in Y: (on Flash/LAN) or on the E2B drive (E2B), For your wait time you get proper performance 
//From all your devices, and or visibility if not otherwise recognized, as long as the drivers are in the folder. 
// 
//Network drive specifies the Server, Share, Login Credentials and the desired Drive letter to mount the share too. 
//Y: is reserved for Files required by the Diagnostic Enviornment, LAN requires the first loaded share to contain 
//Non-Wim files found in the .iso. Flash/E2B can also mount Network shares but Y: must not be used. 
// 
//No Slashes are required when entering the network parameters, unless your username requires a domain prefix 
//you may only connect to one server, and only use one user to login, however shares are only limited by available 
//Drive letters. X: Y: are reserved by the environment, if the computer used has a HDD with windows on it C: will be 
//used, if modern windows then there will be additional partitions loaded if they are not hidden. 
//Advise not to use B:C:D:E:X:Y: 

//========================================================================== 
;//(Mode can be: Flash/E2B/LAN) 
!#Mode @ LAN 
;//(Performance Mode can be: Yes/No) 
!#Perf @ No 
;//(Network Drive Parameters) 
;//(Number of network Shares to mount including Y: if LAN booting) 
!#NumDrv @ 3  
;//(Server to connect to on LAN) 
!#Server @ oc3-omega01  
;//(User name to authenticate with the server) 
!#Usr @ SomeName  
;//(Password to authenticate with the Server) 
!#Pass @ SomePassword  
;//(Drive letter to assign the first share) 
!#DrvLtr @ Y  
;//(Share on server to map to drive) 
!#Share @ OmegaDR  
;//(Repeat DrvLtr and Share lines for as many shares as you are mapping, Do not reuse drive letters) 
!#DrvLtr @ Z  
!#Share @ Data  
!#DrvLtr @ U  
!#Share @ "Manual Backups"  

Je dois dire qu'il n'y a rien vraiment confidentiel à ce sujet afin qu'il puisse être partagé, comme quand J'ai terminé, oui ça va convenir à mon objectif d'avoir // une // image qui peut être configurée dynamiquement pour des utilisations multiples, mais je o prévoyez de le partager afin que d'autres personnes ayant des projets winpe puissent en bénéficier.

Ce projet est en fait une sorte de mise à jour, car j'ai un ensemble d'outils PE3 (basé sur win7), mais j'ai découvert à la dure qu'il ne verrait pas les lecteurs GUID sur un système UEFI. De plus, les scripts utilisés dans mes images PE3 étaient statiques et pendant qu'ils fonctionnaient la plupart du temps, ils ne le faisaient pas parce que la chose exacte que je tapais dans les scripts ne correspondait à aucune nouvelle machine aléatoire. cette fois j'essaie de faire un script de démarrage universel.

+5

Il y a énormément de choses à traiter pour ce qui semble être une question beaucoup plus simple. Peut-être que vous pourriez essayer de trouver un moyen de démontrer votre problème dans un script plus minimal? c'est-à-dire un [mcve]. – 3D1T0R

+2

Qu'attendez-vous de ce code: ** Si var! Count! == Mode **. Assez sûr que c'est là où vous êtes confus. – Squashman

+0

Ce n'est pas ce que j'appelle un [mcve]! – aschipfl

Répondre

0
if var!count!==Share (

seront résolus à

if var1==Share (

en supposant count a la valeur 1.

IF est tout à fait littéral - les deux chaînes de chaque côté de l'opérateur de comparaison sont comparés à la lettre, donc l'instruction est « si la chaîne littérale var1 est égale à la chaîne littérale Partager »

Vous avez besoin le contenu devar1, qui est !var%count%! C'est - deux étapes - d'abord remplacer %count%avec le contenu de count, puis récupérez le contenu du résultat. C'est pourquoi !var! ne doit pas être utilisé pour le cas général value of a variable, mais réservé à l'endroit où cette résolution en deux étapes est requise et lorsque la variable requise est modifiée dans une boucle.

BTW - if a un commutateur /i pour rendre la comparaison insensible à la casse.

set var listera toutes variables commençant var

:EOF est prédéfini comme littéralement "la fin du fichier". goto :eof est prédéfini comme "aller à la fin du fichier" (quittez la routine en cours) et vous risquez de rencontrer des problèmes si vous définissez votre propre étiquette :eof - par exemple, goto eof atteindra heureusement votre étiquette, mais goto :eof quittera la routine (une autre raison pour laquelle je n'utilise pas la syntaxe goto :label)

+0

Merci Magoo, il y a quelques bonnes informations dont j'ai besoin, pas des moindres, c'est le switch "if/i". Le paramètre 'if var! Count! == Share (' tid bit n'était pas seulement connu, mais exploité.pour cette utilisation, une boucle For/f définit ces variables à partir d'un fichier et cette partie fonctionne. le travail n'utilise pas IF pour faire correspondre la variable générée à la volée var! count! à une variable déclarée et pour définir sa valeur si la condition est vraie, le problème est que les instructions "if", peu importe comment je les ai finalisées, n'évaluent pas En prenant quelques conseils, je posterai bientôt un exemple plus simple. –