-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathTestUtils.java
More file actions
44 lines (40 loc) · 1.64 KB
/
TestUtils.java
File metadata and controls
44 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gov.loc.repository.bagit;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class TestUtils {
public static boolean isExecutingOnWindows(){
return System.getProperty("os.name").contains("Windows");
}
/**
* walk a directory and make sure that files/folders are hidden if they start with a . on windows.
*
* @param startingDir the directory to start walking
* @throws IOException if there is a problem setting the file/folder to be hidden
*/
public static void makeFilesHiddenOnWindows(Path startingDir) throws IOException {
if (isExecutingOnWindows()) {
Files.walkFileTree(startingDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException{
String name = dir.getFileName().toString();
if(name.startsWith(".") && !(name.equals(".keep") || name.equals(".bagit"))){
Files.setAttribute(dir, "dos:hidden", Boolean.TRUE);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException {
String name = path.getFileName().toString();
if(name.startsWith(".") && !(name.equals(".keep") || name.equals(".bagit"))){
Files.setAttribute(path, "dos:hidden", Boolean.TRUE);
}
return FileVisitResult.CONTINUE;
}
});
}
}
}