User User name Password  
   
Tuesday 19.8.2025 / 08:28
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > software, operating systems and more > windows - software discussion > need help writing a batch file for the following task:
Show topics
 
Forums
Forums
NEED HELP writing a batch file for the following task:
  Jump to:
 
Posted Message
aweathe
Junior Member
_
15. May 2007 @ 09:47 _ Link to this message    Send private message to this user   
yes the examples i gave are all in order to be 'hits'

and yes the ordering of the filenames is always the same for the two list;
first file:
one letter, two figures, two letters

second file:
two letters, two figures and ".site"?
Advertisement
_
__
Indochine
Senior Member
_
15. May 2007 @ 09:52 _ Link to this message    Send private message to this user   
are there just the two files, or numbers of each? do they have distinctive names / extensions?


On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
15. May 2007 @ 10:04 _ Link to this message    Send private message to this user   
there are two text files with a list in each. the lists in each are much longer than the two lists that I typed, but the format of the file names stay the same.

basically I'm not sure how to write the 'if' statement. I'll give it a go and then it'll be easier for you to correct:

set name1=I17CI
set result1=%name1:~1,2%

set name2=IS17.site
set result2=%name2:~2,3%.

if restult1==result2 (command)
Indochine
Senior Member
_
15. May 2007 @ 10:34 _ Link to this message    Send private message to this user   
I'll give it an indepth look later, but it looks like you're on the right track.

On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
Indochine
Senior Member
_
15. May 2007 @ 23:54 _ Link to this message    Send private message to this user   
Quick string slicing demo

@echo off
REM %Somename:~10,5%
REM
REM would expand the Somename environment variable, and then use only the 5
REM characters that begin at the 11th (offset 10) character of the expanded
REM result. If the length is not specified, then it defaults to the
REM remainder of the variable value. If either number (offset or length) is
REM negative, then the number used is the length of the environment variable
REM value added to the offset or length specified.
REM

REM required: starting at 2nd character (offset 1), use 2 characters
set name1=I17CI
set result1=%name1:~1,2%

REM required: starting at 3rd character (offset 2), use 2 characters
set name2=IS17.site
set result2=%name2:~2,2%

if %result1% == %result2% echo same

REM Saving 2 variables
if %name1:~1,2% == %name2:~2,2% echo also the same

Result:

same
also the same

[edit]

Also, it might be helpful to know what results are going to be interesting to you

(1) A two digit pair in file1 is found one (or more?) time in file 2
(2) Vice versa
(3) The same two digit pair is found in both files
(4) A two digit pair is found in file1 but not file2
(5) Vice versa

And... What is expected... a number in file1 is matched a few or many times in file2, etc...

On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 16. May 2007 @ 00:12

aweathe
Junior Member
_
16. May 2007 @ 07:26 _ Link to this message    Send private message to this user   
Ok i've gotten to a point where i'm stuck. Here's part of the code that i've written:

for /F "delims==" %%s in ('type "%topfolder%\site files\sitefiles.txt"') do (

if %%%l:~1,2%.==%%%s:~2,3% (copy %topfolder%\site files\%%s %topfolder%\%%d\%%l)


Now you can probably see some problems with this... as relating to my last post, the variable %%l is of the form "I17CI" and the variable %%s is of the form "IS17.site".

Now 1. How can I write an if statement to compare the two?
and 2. Is the copy statement going to work? (the variable %%d is of the form "17-Aug-2006")

Thank You!

This message has been edited since posting. Last time this message was edited on 16. May 2007 @ 07:27

Indochine
Senior Member
_
16. May 2007 @ 07:37 _ Link to this message    Send private message to this user   
Originally posted by aweathe:
for /F "delims==" %%s in ('type "%topfolder%\site files\sitefiles.txt"') do (

if %%%l:~1,2%.==%%%s:~2,3% (copy %topfolder%\site files\%%s %topfolder%\%%d\%%l)

Is this a nested loop? Beware!!!

1. too many % signs! loop variables should have two only.

2. where did %%s and %%d come from? They can only exist in loops.

3. that COPY command looks kind weird. You are trying to copy to a folder whose name is generated by variable expansion. Does it exist?







as relating to my last post, the variable %%l is of the form "I17CI" and the variable %%s is of the form "IS17.site".

Now 1. How can I write an if statement to compare the two?
and 2. Is the copy statement going to work? (the variable %%d is of the form "17-Aug-2006")

Thank You![/quote]

On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
16. May 2007 @ 07:46 _ Link to this message    Send private message to this user   
Quote:
[quote=aweathe]for /F "delims==" %%s in ('type "%topfolder%\site files\sitefiles.txt"') do (

if %%%l:~1,2%.==%%%s:~2,3% (copy %topfolder%\site files\%%s %topfolder%\%%d\%%l)

Is this a nested loop? Beware!!!

1. too many % signs! loop variables should have two only.

I put more than two % signs in because I was following the example line you wrote:

%name1:~1,2% == %name2:~2,2%

In this case I would like to replace name1 with %%l and name two with %%s. Is this possible? I think my main problem is that I don't understand what the % symbol means and is used for...

The extra varaibles %%l and %%d are the result of two 'higher for /F loops. I can show you the whole code if you want... but maybe not necessary.


2. where did %%s and %%d come from? They can only exist in loops.

3. that COPY command looks kind weird. You are trying to copy to a folder whose name is generated by variable expansion. Does it exist?
aweathe
Junior Member
_
16. May 2007 @ 07:49 _ Link to this message    Send private message to this user   
Here's the code just in case it makes it easier for you to answer my question: (but likely no need to get into the logic of it)

echo off

REM Run this file from the desktop.
REM Two folders: one containing the site files, and one
REM containing the event data, must be placed on the desktop.

set topfolder=%cd%


echo STEP 1: create sitefile.txt
pause

cd %topfolder%\site files

dir /b > sitefiles.txt


echo STEP 2: create dates.txt
pause

cd %topfolder%\Assign1

dir /b /ad > dates.txt


echo STEP 3: move site files over to correct folders


for /F "delims==" %%d in ('type "%topfolder%\Assign1\dates.txt"') do (

pause

echo %%d

pause

REM line below will work???

cd %topfolder%\Assign1\%%d

ECHO current dir is %cd%

pause

dir /ad /b > locations.txt

for /F "delims==" %%l in ('type "%topfolder%\%%d\locations.txt"') do (

for /F "delims==" %%s in ('type "%topfolder%\site files\sitefiles.txt"') do (

if %%%l:~1,2%.==%%%s:~2,2% (copy %topfolder%\site files\%%s %topfolder%\%%d\%%l)

)
)

del %topfolder%\Assign1\%%d\locations.txt > nul
)


REM STEP 4: clean up

del "%topfolder%\site files\sitefiles.txt" > nul

del "%topfolder%\Assign1\dates.txt" > nul


REM STEP 5: return to desktop

This message has been edited since posting. Last time this message was edited on 16. May 2007 @ 10:02

aweathe
Junior Member
_
17. May 2007 @ 06:35 _ Link to this message    Send private message to this user   
hi Indochine,

I posted a similar question on another forum (computerhope.com) and there's a guy there that's helping me out with this. Thanks for all your help! I can write you back with the solution if you like when I get it.. or maybe this wouldn't be beneficial to you.

You've given me a great jump start to writing batch files. I've really appreciated all your help and time!!!
Indochine
Senior Member
_
17. May 2007 @ 06:58 _ Link to this message    Send private message to this user   
Quote:
I posted a similar question on another forum (computerhope.com) and there's a guy there that's helping me out with this.
He's not called "contrex" by any chance, is he? Aweathe, you can run but you can't hide! ;-)


On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 17. May 2007 @ 07:00

aweathe
Junior Member
_
17. May 2007 @ 06:59 _ Link to this message    Send private message to this user   
yep that's him!
aweathe
Junior Member
_
17. May 2007 @ 06:59 _ Link to this message    Send private message to this user   
do you know him?
Indochine
Senior Member
_
17. May 2007 @ 07:01 _ Link to this message    Send private message to this user   
Originally posted by aweathe:
do you know him?
I know him very well indeed! :-)

On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 17. May 2007 @ 07:01

aweathe
Junior Member
_
17. May 2007 @ 07:02 _ Link to this message    Send private message to this user   
hahaha alright...
Indochine
Senior Member
_
17. May 2007 @ 07:03 _ Link to this message    Send private message to this user   
As in I am he...



On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
Indochine
Senior Member
_
17. May 2007 @ 07:04 _ Link to this message    Send private message to this user   
Did you see "his" code? Did it work?

I bet you were thinking "This new guy contrex seems much more clued-in than that dufus Indochine!" and now you find out we are the same person!!! ;-)




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 17. May 2007 @ 07:06

Advertisement
_
__
 
_
aweathe
Junior Member
_
17. May 2007 @ 07:06 _ Link to this message    Send private message to this user   
I was kinda figuring that... wasn't sure tho! hahahaha Oh well so we're still chatting afterall then! haha... ok I'm working through the code right now, it is becoming clearer and clearer...
 
afterdawn.com > forums > software, operating systems and more > windows - software discussion > need help writing a batch file for the following task:
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2025 by AfterDawn Ltd.

  IDG TechNetwork