Skip to content

ファイルパスの連結などを行うUtility群

Notifications You must be signed in to change notification settings

masatomix/UiPath_Path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library is a custom activity for UiPath.

When using UiPath, I often want to call methods of .NET, such as getting the name of the current directory, base64 encode the file,These activities are the activities that call those methods. It provides the following functions.

Path Utils

Combine Activity

image.png

Combines an array of strings into a path. That is as follows:

{"c:\temp","hogehoge"} → c:\temp\hogehoge
{"temp","hogehoge"} → temp\hogehoge
{"te/mp","hoge\hoge"} → te\mp\hoge\hoge

calls System.IO.Path.Combine method . And calls String.Replace("/", "\\") method to use '/' .

Current Dir Activity

image.png

Gets the current working directory. only calls Directory.GetCurrentDirectory method.

Path Utils Activity

image.png

Specify relative/absolute path and get the following:

Properties Description
DirectoryPath Basically it returns the same as Path.GetDirectoryName() ※.
DirExists returns true if the specified Directory exists (returns false even if it exists if it is a File).
FileExists returns true if the specified File exists (returns false even if it exists if it is a Directory).
FullPath returns full Path.

※ Basically it returns the same as Path.GetDirectoryName(). If an existing directory is specified, even if there is no "\" at the end, the directory path is returned.

For examples:

Path: c:/temp/existsDir/
→
FullPath: c:\temp\existsDir\
DirectoryPath: c:\temp\existsDir


Path: c:/temp/existsDir
→
FullPath: c:\temp\existsDir
DirectoryPath: c:\temp\existsDir   ← The .NET method returns c:\temp


Path: c:/temp/notExistsDir/
→
FullPath: c:\temp\notExistsDir\
DirectoryPath: c:\temp\notExistsDir


Path: c:/temp/notExistsDir
→
FullPath: c:\temp\notExistsDir
DirectoryPath: c:\temp


Path: c:/temp/existsOrNotExistsFile.txt
→
FullPath: c:\temp\existsOrNotExistsFile.txt
DirectoryPath: c:\temp

String Utils

Base64 Encode Activity

image.png

Converts a String to its equivalent string representation that is encoded with base-64 digits. That is as follows:

 var result = Convert.ToBase64String(Encoding.GetEncoding("UTF-8").GetBytes(text));

Base64 Decode Activity

image.png

Converts the specified string, which encodes binary data as base-64 digits. That is as follows:

var resut = Encoding.GetEncoding("UTF-8").GetString(Convert.FromBase64String(text));

Base64 Encode From File Activity

image.png

Converts the String From a file to its equivalent string representation that is encoded with base-64 digits. That is as follows:

var path = context.GetValue(this.Path);
var bytes = ReadFile(path);
var result = Convert.ToBase64String(bytes);

public byte[] ReadFile(string filePath)
{
    using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    {
        var buffer = new byte[fs.Length];
        fs.Read(buffer, 0, buffer.Length);
        return buffer;
    }
}

Convert CRLF Activity

image.png

Convert the line feed code of the given text. Regardless of whether the line feed code of data is LR / LF / CR + LF,It outputs with a line feed code with a check in "Set line feed code". It first converts to CR / CR + LF → LF, and then converts LF to the specified line feed code. That is as follows:

 // It first converts to CR / CR + LF → LF
 trimData = trimData.Replace("\r\n", "\n");
 trimData = trimData.Replace("\r", "\n");

 if (CR) {
     trimData = trimData.Replace("\n", "\r\n");
 } else {
     // do nothing
 }

 if (LF) {
     // do nothing
 } else {
     trimData = trimData.Replace("\n", "");
 }

To JSON String Activity

An activity that converts arbitrary objects to JSON strings. image.png

For example,when you generate and pass the Dictionary object, the Key / Value is output as a JSON string. image.png

That is as follows:

String jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(obj, Formatting.Indented);

About

ファイルパスの連結などを行うUtility群

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages