forked from microsoft/GaitAndBalanceApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.cs
68 lines (56 loc) · 2.25 KB
/
Tools.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
namespace GaitAndBalanceApp
{
static class Tools
{
static char[] underScore = new char[] { '_' };
readonly public static string dateFormat = "yyyyMMddHHmmss";
public static bool parseFileName(string filename, out string identifier, out string exercise, out DateTime date)
{
identifier = null; exercise = null; date = DateTime.Now;
var f = filename.Split(underScore);
if (f.Length < 4) return false;
date = DateTime.ParseExact(f[f.Length - 3], dateFormat, System.Globalization.CultureInfo.InvariantCulture);
exercise = f[f.Length - 2];
identifier = f[0];
for (int i = 1; i < f.Length - 3; i++)
identifier += "_" + f[i];
return true;
}
public static bool parseSampleFileName(string filename, out string identifier, out string exercise, out DateTime date)
{
identifier = null; exercise = null; date = DateTime.Now;
var f = filename.Split(underScore);
if (f.Length < 4) return false;
date = DateTime.ParseExact(f[f.Length - 3], dateFormat, System.Globalization.CultureInfo.InvariantCulture);
exercise = f[f.Length - 2];
identifier = f[0];
for (int i = 1; i < f.Length - 3; i++)
identifier += "_" + f[i];
return true;
}
public static string getPath(string path)
{
var dlg = new CommonOpenFileDialog();
dlg.Title = "Select data folder";
dlg.IsFolderPicker = true;
dlg.InitialDirectory = path;
dlg.AddToMostRecentlyUsedList = false;
dlg.AllowNonFileSystemItems = false;
dlg.DefaultDirectory = path;
dlg.EnsureFileExists = true;
dlg.EnsurePathExists = true;
dlg.EnsureReadOnly = false;
dlg.EnsureValidNames = true;
dlg.Multiselect = false;
dlg.ShowPlacesList = true;
if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
{
var folder = dlg.FileName;
return folder;
}
return null;
}
}
}