1.

Solve : if here are more than (..) file?

Answer»

hi
i have a problem
i want to DIR from current folder to see if there are more than 6 .swf files and if there are more program should go to END AND CLOSE but if there are less than 6 .swf files check the second file types ( flv and jpg)
if there is any amount of these files program should do 2 job
1- make a COPY of them to d:\files
2-go to second step(step 5)
thanks I always like PEOPLE to at least make an attempt at starting a script. So I will at least give you an idea on how to start it.
Code: [Select]for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
do the rest of your stuff here
)dear Squashman
thanks for the reply

before starting this topic i tried my best ! and cuz i am beginner so there was no hope !
i tried below script to count how many swf files exited in the current folder
Quote

dir "*.swf" | find /i "file"

and it worked but below script is not working i dont know why

Quote
for /f "tokens=1 delims= " %%a in ('dir *.swf ^| find "File(s)"') do set var=%%a
if %var% lss 6 goto step2
if %var% more 6 goto step3

:step2
for /f "tokens=1 delims= " %%G in ('dir *.jpg *.flv ^| findstr /R /C:"File(s) ') do (
xcopy %%G d:\files /s /i

:step3
:end
I gave you the code for when it is greater than 6 and the code for the FOR loop. You have refused to use both. Why?

There is no such thing as a MORE compare operator.
Open up a command prompt and type: if /?
dear Squashman
its too complicated for me ! CANT you do the rest believe it or not if i could figure it out myself i would have done that

and something elas i tried this script and it did nothing why ?
there were just 2 swf files !!
Quote
for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
IF %%G LSS 6 GOTO :step2
)
::step2
echo= > comments.txt
pause
:EOF
:end
please helpYou don't need a :EOF label to go to. GOTO :EOF is the same as using the exit command.
Your goto for step 2 does not work because your label has 2 colons in front of it.ok now i tried this one and it worked but it looks ugly to me can someone make it better or fix the problems?
working script
Quote
for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
IF %%G LSS 6 GOTO :step2
)
:step2
IF EXIST *.jpg IF EXIST *.flv GOTO step3
IF not EXIST *.jpg IF not EXIST *.flv GOTO EOF
:step3
xcopy *.jpg d:\files
xcopy *.flv d:\files
pause
:EOF
:end

problems=
1-if some ( jpg or flv ) files are exited in sub-directories they cant be find or copy
2- script is not sharp enough and is not working exactly(SOMETIMES good sometimes bad !)ok my other topic closed so i came here
but to me its a different question !!
====================
here is my topic please read it and if you can help

hi
i have a problem with my batch script
i want to DIR and check to see if these files are exist or not


Quote
myflash.rar source.fla newfile.swf movie.flv *.reg

if they are exist (mostly in source folder) go to finish and end but if there are not at least one of those files exist move everything from source folder to extra folder

important=
1-its not Necessary for existence of all of those files at the same time
2-but at least one of those should be in source folder
3-if there were not at lease one of those files move everything from source folder to extra folder

my script is here but i dont know why its not working and how should i fix it

Quote

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s myflash.rar source.fla newfile.swf movie.flv *.reg') do (
IF EXIST %%a GOTO finish
IF NOT EXIST %%a GOTO nofile

:nofile
move "source\*.*" "extra"
:finish
:end
)
1) You need to use the /B switch with the DIR command
2) don't use a space as a delimiter.
3) move your closing parenthesis after your IF statements.
4) You should put quotes around your variable names when dealing with file names and directory paths.dear Squashman
i tried what you said or at least what i got from your answer but it didn't worked
Quote
1) You need to use the /B switch with the DIR command
you man dir/s/B i tried this one too dir/B

Quote
2) don't use a space as a delimiter.
where? you mean space in line 4 in my previous post? i removed it !
Quote
3) move your closing parenthesis after your IF statements.
which one? the one in line 2 or 9 ? if i remove parenthesis in line 9 ) it wont be able to run it !

4) You should put quotes around your variable names when dealing with file names and directory paths.
i hope you mean names in line 2 . right? i put quotes around them
"myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"

my final batch is below and it still is not working . i don't know which part is missing !

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s/B "myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"') do (
IF EXIST %%a GOTO finish
IF NOT EXIST %%a GOTO nofile
)
:nofile
move "source\*.*" "extra"
:finish
:end

1) In regards to using DIR /B /S. Do you understand why you need to use both of those switches. Just type DIR /S at a cmd prompt, then type DIR /B /S and you should see why.
2) NO! You are using a Space as a delimiter in your FOR LOOP! Either close up the space or get rid of the delims option all together.
3) Of course the last one. You need to end the code block in the correct spot. I didn't say REMOVE it. I said move it after your IF statements.
4) No! Those file names don't have any spaces in them. If they did you would need quotes. I specifically said VARIABLES! What do you think is going to happen to your IF EXIST test if their is a space in the directory path.Quote
1) In regards to using DIR /B /S. Do you understand why you need to use both of those switches. Just type DIR /S at a cmd prompt, then type DIR /B /S and you should see why.

i just wanted my bat to SEARCH and look into sub-directories too !

Quote
3) Of course the last one. You need to end the code block in the correct spot. I didn't say REMOVE it. I said move it after your IF statements
.

brilliant my friend you are truly a master
it worked like a charm
Quote
4) No! Those file names don't have any spaces in them. If they did you would need quotes. I specifically said VARIABLES! What do you think is going to happen to your IF EXIST test if their is a space in the directory path.
i think error was not because of those file names i didn't change them and it solved
just that bad parenthesis )
and something else= i replaced line 3 with 4 and it solved !!
my final working script is below
thanks dear master Squashman

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s/B "myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"') do (
IF NOT EXIST %%a GOTO nofile
IF EXIST %%a GOTO finish
)
:nofile
move "source\*.*" "extra"
:finish
:end
Well I hope your paths don't have spaces in them because it won't work if it does.


Discussion

No Comment Found