Search found 36 matches

by greenfinch
18 Aug 2008 10:36
Forum: DOS Batch Forum
Topic: Handling Dates - Only checking Day and not all Date
Replies: 6
Views: 11234

Ah, sorry, I assumed like you that date comparisons worked regardless of format. But from messing around with this, IF just treats the whole string as a number, not a date, ignoring / or - separators. So you need to parse the date into a simple number, and your logic will still work: FOR /F "us...
by greenfinch
18 Aug 2008 05:57
Forum: DOS Batch Forum
Topic: Handling Dates - Only checking Day and not all Date
Replies: 6
Views: 11234

1. Check that you have the right date format - if you do echo %date% I assume you date format is dd-mm-yyyy This can vary - mine is dd/mm/yyyy 2. You first section: IF %DATE% EQU 01-01-2008 GOTO NORMAL if %date% GTR 23-09-2008 GOTO SIM The first line is EQU so NORMAL is only used if date = 01-01-200...
by greenfinch
17 Aug 2008 18:45
Forum: DOS Batch Forum
Topic: Multiple commands per line
Replies: 5
Views: 16256

See http://technet.microsoft.com/en-us/libr ... 37438.aspx

&& means 'do the next one if the last one completed OK'
by greenfinch
17 Aug 2008 10:40
Forum: DOS Batch Forum
Topic: String Manipulation Error
Replies: 2
Views: 7015

Same problem as the main topic you posted - line breaks confuse DOS/CMD processor: @Echo off setlocal enabledelayedexpansion set check=some set fourchars= FOR /F "TOKENS=1,2 DELIMS=_." %%a IN ("file_somenamev1.3.zip") do (set token1=%%a&set token2=%%b) echo to...
by greenfinch
17 Aug 2008 10:27
Forum: DOS Batch Forum
Topic: String Manipulation/String Tokenization in DOS
Replies: 5
Views: 11195

You can't quite format syntax that way, with line breaks to separate commands, if you are within a FOR command Commands can be separated instead using && but this is hard to read Instead, break things into subroutines and call them like this: setlocal @Echo off set checkfilename=filename set...
by greenfinch
13 Aug 2008 11:00
Forum: DOS Batch Forum
Topic: extracting directory name from list
Replies: 1
Views: 5972

Hi Oh, I'm not sure what you are aiming to get from this first line: set filelist=.\anc_extraction_fifo11x512_fast_behavioral.bat .\anc_extract_divi\anc-out-y_in.txt Is .\anc_extraction_fifo11x512_fast_behavioral.bat supposed to do something to .\anc_extract_divi\anc-out-y_in.txt to generate a filel...
by greenfinch
13 Aug 2008 10:56
Forum: DOS Batch Forum
Topic: String Manipulation/String Tokenization in DOS
Replies: 5
Views: 11195

Does this help?:

Code: Select all

FOR /F "TOKENS=1,2 DELIMS=_." %%a IN ("file_somenamev1.3.zip") do (set token2=%%b)
set fourchars=%token2:~0,4%
echo %fourchars%


This page is very useful:
http://www.dostips.com/DtTipsStringMani ... LeftString
by greenfinch
23 Jul 2008 20:50
Forum: DOS Batch Forum
Topic: Ignore blank lines and set lines to variables
Replies: 1
Views: 9594

Hi Tigers, Had a mess around with this - ignored the EOL for blanks lines because it seems it wasn't needed. The important bit is "delims=" which makes each line a token. The default delims are space and tab which is no use here - see m The cleanup subroutine uses "delims= " (spa...
by greenfinch
23 Jul 2008 11:12
Forum: DOS Batch Forum
Topic: "FOR" help
Replies: 5
Views: 11353

Just about right, yes! In the first example, you need to specify a filename to output to within %a, e.g. FOR %a IN (%USERPROFILE%\desktop %USERPROFILE%\documents) DO echo start %CD% >> %a\filename.txt Your final example is more fiddly: FOR /f "delims=, tokens=1-3" %a IN ("...
by greenfinch
21 Jul 2008 06:40
Forum: DOS Batch Forum
Topic: "FOR" help
Replies: 5
Views: 11353

I found this very useful:
http://www.robvanderwoude.com/for.html

It helps to think:
FOR every TOKEN in (list, file, whatever) DO (something involving the token)

That's the basic format. The delims=, tokens= and so on basically let you get the right token to do things to - worry about that later.
by greenfinch
21 Jul 2008 06:34
Forum: DOS Batch Forum
Topic: Brackets with If & For commands
Replies: 2
Views: 7441

Hi Tigers, See m Generally use && "Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully." e.g. FOR /D %variable IN (s...
by greenfinch
17 Jul 2008 10:55
Forum: DOS Batch Forum
Topic: String variable substitution
Replies: 7
Views: 12436

This explains it quite well: m Instead of % you use ! to indicate a variable but these are only recognised if you use setlocal ENABLEDELAYEDEXPANSION In the case of set refoutput=!output:%nextcommand% =! it delays the expansion of !output! until it's expanded %nextcommand% The space before the =! is...
by greenfinch
17 Jul 2008 10:46
Forum: DOS Batch Forum
Topic: move Files from different folders
Replies: 1
Views: 5942

Hi Prashob, save this as something.cmd in D:\PRASHOB\LY-01\jurion\test3\New\output1\XML and run it I assume that your target folders already exist (i.e. jurion, vt, pm, cas, ls) setlocal REM targetpath contains folders jurion, vt, pm, cas, ls set targetpath=d:\temp FOR /f "delims=" %%f in ...
by greenfinch
17 Jul 2008 10:24
Forum: DOS Batch Forum
Topic: Remove pattern from end of line?
Replies: 1
Views: 5499

An inspiring session of washing the dishes led to the idea that I need to reverse the input string, then I can use FOR on it with delims of [(- Reverse it again and voila! SETLOCAL CALL :reverse %1 FOR /f "tokens=1* delims=[(-" %%a in ("%reverse%") DO SET output=%%b R...
by greenfinch
17 Jul 2008 10:15
Forum: DOS Batch Forum
Topic: String variable substitution
Replies: 7
Views: 12436

Got it. I had wanted to something like this a few weeks ago, and only just worked it out now - so thank you!

Code: Select all

setlocal ENABLEDELAYEDEXPANSION 

set output=%*
set nextcommand=%1 %2
set refoutput=!output:%nextcommand% =!
echo %refoutput%