1 /*
2 * Copyright 2024 Hochschule Luzern Informatik.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package ch.hslu.exercises.sw11.ex4.findfile;
17
18 import java.io.File;
19 import java.util.Collections;
20 import java.util.concurrent.ExecutorService;
21 import java.util.concurrent.Executors;
22
23 import org.slf4j.LoggerFactory;
24 import org.slf4j.Logger;
25
26 /**
27 * Codevorlage für eine Dateisuche.
28 */
29 public final class FindFile {
30
31 private FindFile() {
32 }
33
34 private static final Logger LOG = LoggerFactory.getLogger(FindFile.class);
35
36 /**
37 * Sucht ein File in einem Verzeichnis.
38 *
39 * @param name Name des Files.
40 * @param dir Verzeichnis.
41 */
42 public static void findFile(final String name, final File dir) {
43 final File[] list = dir.listFiles();
44 if (list != null) {
45 for (File file : list) {
46 if (file.isDirectory()) {
47 findFile(name, file);
48 } else if (name.equalsIgnoreCase(file.getName())) {
49 LOG.info(file.getParentFile().toString());
50 return;
51 }
52 }
53 }
54 }
55 }