Go over directories in Uipath - search

I want to go over a directory and delete all files older than x, in Uipath. My problem is that I don't know how to go over another folder that may be inside.

Here's how to enumerate over each file in a folder and all potential subfolders: Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories).
You may then use File.GetAttributes(file) to return a FileAttributes object which will expose detailed information about the file"s creation date, for example (more info here).

Use UiPath.Core.Activities.InvokePowerShell
Commandtext (Sample):
("Remove-Item -Path " + Path.Combine([YOURPATH], "*.*") + " -Force -Recurse")
This removes all files in the directory recursive.

Related

How can I set an universal working directory?

I'm setting up a new algorithm and I want to share it on another computer. How can I set paths with only the folder name, for example.
I've tried to use the function os.chdir(path), but I don't achieve to reach my folder when I'm not using a 'root path' like C:/../../folder.
os.chdir(../folder_name)
By doing os.chdir(../folder_name), you are referring to the parent dir of the current directory.
You probably are looking for the os.chdir(./folder_name), with one dot? This is the current directory, where your script stands.
More here: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Update: After clarification in the comments, you want to refer to folder_name from one of its subfolder (/folder_name/library). Then it is indeed .. that you should use, but .. only:
os.chdir(..)

Deleting a file IF any folders in current directory contain a keyword using batch

I am trying to write a batch file that takes a backup using temporary folders and a "sub-batch" file that needs to be deleted once all backups are completed.
The method I'm trying to use copies a batch file to the main directory, opens multiple instances of this batch which create "temp" folders, then they remove the temp folder once they are done their business.
I want to implement a command at the end of the sub-batch that checks if any folders with the word "temp" exist in the directory, then delete the sub-batch if none exist.
I have tried many iterations, but this is what I kind of ended at before asking this question:
rd %TempFolder% /S /Q
cd C:\BackupDirectory
if exist C:\BackupDirectory\*_Temp_*\ goto :unconnect
del subBatch.bat
:unconnect
I realize that this won't work, but I can't find a good way to find the string "temp" in the sub-directory name.
Any help is appreciated.

I want to copy files from temporary folder to in my c drive by creating new folder

if FileCopy(ExpandConstant('{tmp}\SPECTRUMJOBS_Data.MDF'),
ExpandConstant('C:\Program Files\Microsoft SQL Server\MSSQL11.LOGISTICS\MSSQL\DATA\SPECTRUMJOBS_Data.MDF'),
False) then
I tried the above one but I am not able to copy because there is no folder named DATA in the location.
so please help me to copy the DATA folder and the file
To force creation of directories you can use (text is from InnoSetup help):
Prototype:
function ForceDirectories(Dir: string): Boolean;
Description:
Creates all the directories along the specified directory
path all at once. If the first directories in the path do exist, but
the latter ones don't, ForceDirectories creates just the ones that
don't exist. Returns True if successful, False otherwise.
InnoSetup documentation is at ishelp
You answered yourself. If there is no folder DATA in folder MSSQL, the folder must be created first.
And... if there is no folder MSSQL in folder MSSQL11.LOGISTICS, that folder must be created first.
And so on...
Now read the above sentences in reverse order, and you're done.

Move directory using C#

I'm trying to cut a folder. I've tried directoy.move(string source,string dest) & directoryinfo.moveto(dest) but in both case an exception was thrown "Source and destination path must have identical roots. Move will not work across volume".
You cannot move files and folders across different volumes with Directory.Move. You have to create the directory at the destination, recursively copy the files across then, on success, delete the files at the source or, as Tim suggested in the comments below, recursively create the directory structure then move the files across with File.Move.

VBA - How to get the last modified file or folder in a directory in Excel 2010

What I want to do is more complex than selecting a file from a list of files. I will start in a directory, then I want to change to the most recently modified directory. I then want to repeat that process in a sub-directory, and then, inside of that, I want to select the most recently modified excel file and open it.
What is the best approach to do this?
What objects / methods should I be looking into?
The simplest function is
FileDateTime(pathname)
where pathname can be a directory for folder.
Alternatively, you can use the FileSystemObject object, DateLastModified property:
Dim fileModDate As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(<filenamestringhere>)
fileModDate = f.DateLastModified
All of the above can be explored in VBA help.

Resources