예제 #1
0
        public void Directory_Copy()
        {
            var          tmpSrc     = GetNewFileNameOnTempPath("");
            var          tmpSrcInfo = FileSystem.DirectoryFromPath(tmpSrc);
            const string fileName   = @"temp.txt";

            FileSystem.WriteText(FileSystem.CombinePath(tmpSrc, fileName), "test");

            var tmpDest = GetNewFileNameOnTempPath("");

            FileSystem.CopyDirectory(tmpSrcInfo, tmpDest);
            Assert.IsTrue(FileSystem.DirectoryExists(tmpSrc));
            Assert.IsTrue(FileSystem.DirectoryExists(tmpDest));

            var destFileName = FileSystem.CombinePath(tmpDest, fileName);

            Assert.IsTrue(FileSystem.FileExists(destFileName));
            Assert.AreEqual("test", FileSystem.ReadText(FileSystem.FileFromPath(destFileName)));
        }
예제 #2
0
        public static string AbsolutePath(string path, string hintPath = null)
        {
            //If the path is absolute path no need to transform.
            if (Path.IsPathRooted(path))
            {
                return(path);
            }

            var session = Dynamo.Events.ExecutionEvents.ActiveSession;

            if (session != null && !string.IsNullOrEmpty(session.CurrentWorkspacePath))
            {
                var parent   = Path.GetDirectoryName(session.CurrentWorkspacePath);
                var filepath = Path.Combine(parent, path);
                //If hint path is null or file exists at this location return the computed path
                //If hint path doesn't exist then the relative path might be for write operation.
                if (FileSystem.FileExists(filepath) || string.IsNullOrEmpty(hintPath) || !FileSystem.FileExists(hintPath))
                {
                    return(Path.GetFullPath(filepath));
                }
            }

            return(string.IsNullOrEmpty(hintPath) ? path : hintPath);
        }