Maybe someone a can help me with this.
I am trying to read about 30 or more directories in a directory.
Each one of these 30 directories have many jpg files with-in them.
I want to copy certain jpg files to another directory.
The jpg files that I want to copy have the last 7 characters are 220.jpg
which I can use the RIGHT$(file,7)
this part I know how to do. If I can only find the file.
I am just having problems reading the directory and finding and reading the directories with-in the directory to find the files.
			
			
			
				I am selecting off MP3 and WMA's, but this does parse subdirectories and goes down an entire chain:
SUB GetSubDir(SubDir:STRING, Path:STRING, Ext:STRING)
DEF filename, fullname, temp:STRING
DEF dir, attrib:INT
temp = Path + "*.*"
dir = FINDOPEN(temp)
IF (dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF (attrib & @file_directory)
			IF (filename <> "") AND (filename <> ".") AND (filename <> "..")
				GetSubDir(SubDir,Path + filename + "\\",Ext)
			ENDIF
		ELSE
			Ext = UCASE$(RIGHT$(filename,3))
			IF (filename <> "") AND (filename <> ".") AND (filename <> "..") AND (Ext = "MP3" OR Ext = "WMA")
				cnt = cnt + 1
				fullname = path + filename
				WRITE Ofile, fullname
				dcnt = dcnt + 1
			ENDIF
		ENDIF
	UNTIL filename = ""
ENDIF
FINDCLOSE dir
IF dcnt > 0
	temp = q + "MP3" + CD_Num + qcq + SubDir + qc + LTRIM$(STR$(dcnt)) + c
	WRITE Ofile, temp
	dcnt = 0
ENDIF
RETURN
ENDSUB
I hope this points you in the right direction.
Bill
			
			
			
				This is way over my knowledge, I wouldn't even know where to start on this.
I can see where to exchange the mp3 and wma files to jpg.
but to only copy the jpg files with the last 7 ending characters of 220.jpg and place them in another directory is another thing all togather.
I guess I will have to go back and try and figue out just how to place this in the basic script.
			
			
			
				This should do exactly what you are looking for:
OPENCONSOLE
GetSubDir("C:\\Starting\\SubDir\\")
END
SUB GetSubDir(Path:STRING)
DEF filename, fullname, temp:STRING
DEF dir, attrib, fail:INT
fail = TRUE  /* (if fail=FALSE existing files will be overwritten) */
temp = Path + "*.*"
dir = FINDOPEN(temp)
IF (dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF attrib & @file_directory
			IF filename <> "" AND filename <> "." AND filename <> ".."
				GetSubDir(Path + filename + "\\")
			ENDIF
		ELSE
			Ext = UCASE$(RIGHT$(filename,7))
			IF filename <> "" AND filename <> "." AND filename <> ".." AND Ext = "220.JPG"
         IF COPYFILE(Path + filename, "C:\\220\\" + filename, fail)
            'copying file succeeded
            PRINT filename, " Copied"
         ELSE
            'copying file was not succesfull
            PRINT filename, " failed copy"
         ENDIF
			ENDIF
		ENDIF
	UNTIL filename = ""
ENDIF
FINDCLOSE dir
RETURN
ENDSUB
It looks for 220.JPG in any subdirectory under the Path you send as a starting point and the copies it to C:\220 (you must change this to where you want the files to go).  You may also want to change the fail variable depending on whether you want to overwrite existing files or not.
Modified on 01-12-2010 at 9:03PM CDT.
Bill
			
			
			
				I am sorry, but where do you enter the starting point path
			
			
			
				I'm not sure exactly what you need but bilshin example is fine.
So i guess you have main folder which have subfolder and in this subfolder you have 30 jpg images.
And you want copy one of this jpg files to another folder somwhere on disk,right?
Current directory(folder) name you can have with somwthing like this:
'Get directory name with dirsize=255(API function)
GetCurrentDirectoryA(255,dirname)
dir=FINDOPEN(dirname+"\*.jpg")  
IF dir
	filename = FINDNEXT(dir)
	FINDCLOSE dir
Endif	dirname is string and as you see i add extension jpg.
From CB help:
QuoteFINDNEXT function
After a directory is successfully opened with the FINDOPEN function use FINDNEXT to retrieve the filenames in a loop. FINDNEXT returns an empty string when all of the file names have been retrieved. The syntax of FINDNEXT is:
name = FINDNEXT(handle)
Handle is the integer value returned by FINDOPEN.
I know this is from CB but i think that same thing work for Emergence to.
all best
Aurel
			
				Quote from: oneplace2u on January 12, 2010, 02:16:09 PM
I am sorry, but where do you enter the starting point path
this is what Iam running, but it does nothing
it builds and runs but not files are copied.
I changed the UCASE$ to LCASE$, it didn't seem to make any differants
openconsole
DEF dir:UINT
SUB GetSubDir(Path:STRING)
DEF filename, temp:STRING
DEF dir, attrib, fail:INT
fail = TRUE  /* (if fail=FALSE existing files will be overwritten) */
temp = Path + "*.*"
dir = FINDOPEN("c:\\work\\jpgfolder")
IF (dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF attrib & @file_directory
			IF filename <> "" AND filename <> "." AND filename <> ".."
				GetSubDir(Path + filename + "\\")
			ENDIF
		ELSE
			Ext = LCASE$(RIGHT$(filename,7))
			IF filename <> "" AND filename <> "." AND filename <> ".." AND Ext = "250.jpg"
         IF COPYFILE(Path + filename, "C:\\work\\250\\" + filename, fail)
            'copying file succeeded
            PRINT filename, " Copied"
         ELSE
            'copying file was not succesfull
            PRINT filename, " failed copy"
         ENDIF
			ENDIF
		ENDIF
	UNTIL filename = ""
ENDIF
FINDCLOSE dir
RETURN
ENDSUB
print "Press Any Key To Close"
closeconsole
end
			 
			
			
				Uff...you make little bit weird thing.
You create declared sub (function) with name 
QuoteSUB GetSubDir(Path:STRING)
and then you call same function inside this function on line 17
      GetSubDir(Path + filename + "\\")This makes no sense to me.
I think that dont work on this way.
And on the end you forget add:
print "Press Any Key To Close"
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
ENDi will study this closer...
			
				Zlatko
Quoteand then you call same function inside this function on line 17
Code:
      GetSubDir(Path + filename + "\\")This makes no sense to me.
That's how you recurse nested directories.
oneplace2u 
The main problem is that the SUB GetSubDir(Path:STRING) subroutine is never called in the program.
The part of the program that is being executed is:
openconsole
DEF dir:UINTsubroutines have to be called
In your case it should be look something like this:
openconsole
DEF dir:UINT
GetSubDir("c:\\")
print "Press Any Key To Close"
waitcon
CLOSECONSOLE
END
SUB GetSubDir(Path:STRING)
........
return
endsubI strongly suggest you read the section of the help file covering subroutines .
Larry
			
				Yes Larry you right i forget to tell you that.
Function is not called ::)
			
			
			
				So here is simple example which is (i hope) easier to understand.
Create new folder on C with name work and create inside this folder , subfolder with name jpgfolder.
Put in this subfolder jpg image with name wcircle.jpg
Then create another folder on C with name imgfolder.This will be destination folder.
' copy jpg from one folder to another ----------------------------
DEF dir:INT
DEF filename,temp,dirname,destination:STRING
DEF attrib, fail,error:INT
DEF Path:STRING
OpenConsole
dirname="c:\\work\\jpgfolder\\"
'fail = TRUE  /* (if fail=FALSE existing files will be overwritten) */
dir=FINDOPEN(dirname+"\*.jpg")  
IF dir
	filename = FINDNEXT(dir)
	FINDCLOSE dir
Endif
	
MessageBox 0,"Filename:"+filename,"JPG file"
Path=dirname+filename
MessageBox 0,"FilePath:"+Path,"file Path"
destination="c:\\imgfolder\\"+filename
'temp = Path + "*.*"
'dir = FINDOPEN("c:\\work\\jpgfolder")
IF destination <> ""
   
         error=COPYFILE(Path, destination, 0)
			IF error = 0
            'copying file not succesfull
            PRINT filename, "Failed Copy..."
			ELSE
            'copying file was succesfull
            PRINT filename, " File copied..."
			ENDIF
       
ENDIF
  
print "Press Any Key To Close..."
DO
UNTIL INKEY$ <> ""
CloseConsole
END 
I hope that this will help and read EB user guide... ;)
Zlatko
			
			
			
				I added what you need before the subroutine.
Give that a try.
Bill
			
			
			
				Thank you Guys
This script works great:
OPENCONSOLE
dirname="c:\\work\\jpgfolder\\"
GetSubDir("c:\\work\\jpgfolder\\")
END
SUB GetSubDir(Path:STRING)
DEF filename, dirname:STRING
DEF dir, attrib, fail:INT
fail = TRUE  /* (if fail=FALSE existing files will be overwritten) */
dirname = Path + "*.*"
dir = FINDOPEN(dirname)
IF (dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF attrib & @file_directory
			IF filename <> "" AND filename <> "." AND filename <> ".."
				GetSubDir(Path + filename + "\\")
			ENDIF
		ELSE
			Ext = UCASE$(RIGHT$(filename,7))
			IF filename <> "" AND filename <> "." AND filename <> ".." AND Ext = "250.JPG"
         IF COPYFILE(Path + filename, "C:\\220\\" + filename, fail)
            'copying file succeeded
            PRINT filename, " Copied"
         ELSE
            'copying file was not succesfull
            PRINT filename, " failed copy"
         ENDIF
			ENDIF
		ENDIF
	UNTIL filename = ""
ENDIF
FINDCLOSE dir
RETURN
ENDSUB
print "Press Any Key To Close..."
DO
UNTIL INKEY$ <> ""
CloseConsole
waitcon
END
			
			
			
				oneplace2u 
When posting code, highlight all the code and then click the # button above the text box.
It makes your code easier to read and separate from your narrative.
I fixed your 2 previous code postings.
Larry
			
			
			
				You might want to move:
print "Press Any Key To Close..."
DO
UNTIL INKEY$ <> ""
CloseConsole
before the first END or:
OPENCONSOLE
dirname="c:\\work\\jpgfolder\\"
GetSubDir(dirname)
print "Press Any Key To Close..."
DO
UNTIL INKEY$ <> ""
CloseConsole
END
That way it will be more like what the example was designed to do.
Bill