The ability to make a copy folder in a program is easy to write with recursion. Then I want someone (who knows it) to implement a similar, seemingly not smooth, recursive code that throws out the Replication folder:
public Shared Sub copydirectory (source As String, destination as String) If Directory.ex ists (destination) = False Then Try directory.createdirectory (destination) Catch ex as Exception Logger . Logerror (Logger.SourceType.Application, "Copy Build Process:cannot Create folder:" & destination) return E nd Try end If to each paths as String in directory.getdirectories (source) copydirectory (Paths, Path.Combine (DE Stination, Paths. Substring (Paths. Lastindexofany ({"" C, "/" C}) + 1)) Next for each files as String in Directory.GetFiles (source) Try file.c opy (Files, path.combine, destination, files. Substring (Files. Lastindexofany ({"C,"/"C}) + 1"), True) _copiedfiles + = 1 Catch ex as Exception Logger.logerror (logger.so Urcetype.application, "Copy build process:cannot Copy file: & Files" End Try Next end Sub
Recursive programs are very simple and beautiful, right? Then I wrote a way to search the file in a folder, and it was recursive, so I threw it out here:
' <summary> ' Search the specified file in the folder and its sub folders and return their full path name.
Empty string if not found. ' </summary> ' <param name= ' fileName ' >the file to search (no folder) .</param> ' <REMARKS>&L t;/remarks> public Shared Function searchfile (folder As String, FileName as String) As String If directory.exists (fol Der) = False Then return String.Empty fileName = FileName.Trim.ToLower If filename.indexofany ({"C,"/"C}) >= 0 Then filename = getfilename (filename) End If Dim list () as String = Directory.GetFiles (folder) for I as Integer = 0 to list. GetUpperBound (0) If GetFileName (list (i)).
Trim.tolower = fileName Then return list (i) Next Dim directories () as String = directory.getdirectories (folder) For I as the Integer = 0 to directories. GetUpperBound (0) Dim return_file as String = searchfile (Directories (i), fileName) If return_file. Length > 0 Then return return_filE Next return String.Empty end Function
GetFileName, I wrote it myself. A way to remove a path that leaves only the file name and extension.
These two pieces of code are too simple, so I think there is no place to explain (in fact, is ready to leave the work).