I want to be able to reference the iMacros folder from my javascrip script in order to write:
retcode = iimPlay(folder + "/macro1.iim");
retcode = iimPlay(folder + "/macro2.iim");
instead of
retcode = iimPlay("test/macro1.iim");
retcode = iimPlay("test/macro2.iim");
I know it is possible in vbs but I don't know if that is the case in javascript.
it works in a similar way with javascript, here is example of the code:
var folder="c:\\data\\"
iimPlay(folder+"1.iim");
this code will run the 1.iim script from c:\data folder
You can make use of inbuilt !FOLDER_DATASOURCE variable to get folder of current javascript macro.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
var folderPath = iimGetExtract();
//Remove 'Datasources' from end of folder path string
folderPath = folderPath.slice(0,-11);
//Append 'Macros' to end of above path
folderPath = folderPath+"Macros\\";
alert(folderPath);
Performing above steps in single command.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Remove 'Datasources' from end of folder path string and append 'Macros'
var folderPath = iimGetExtract().slice(0,-11)+"Macros\\";
alert(folderPath);
Another possible approach is to replace 'Datasources' with 'Macros' in folder path.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Replace 'Datasources' with 'Macros' in folder path string
var folderPath = iimGetExtract().replace("Datasources","Macros\\");
alert(folderPath);
However it may create problem if folder path contains 'Datasources' anywhere else. You may use any of above methods as per your choice.
Once you get folder path of 'Macros' folder, you can use it like.
retcode = iimPlay(folderPath + "macro1.iim");
Related
I need to do list of assets that are inside a list of directories. So, the step-by-step is this:
The user selects a Parent Directory which contains all the other
directories with assets and then makes a list with these directories;
Then, I have to access the first directory of the list and make
another list with the assets inside the directory.
The problem is that when I run the code for the first time without the loop, it made the list of directories perfectly. But when I try to run with the loop the Scripting Listener says:
"Error occurred in anonymous codeblock; filename:
E:\MUVA\MaxScript\teste.ms; position: 371; line: 9
-- No "map" function for "\*""
And then I have to restart the 3ds Max and delete the loop for the first step works again. Maybe there's something wrong with my logical that I'm not seeing.
dirPath = getSavePath caption: "SELECT THE PARENT DIRECTORY"
dirList = getDirectories dirPath + "\*"
print ("Directories: " + dirList)
for dir in dirList do(
assetsPath = dir + "\*.max"
assetsList = getFiles assetsPath
print ("List of assets: " + assetsList)
)
And yes, my logical was wrong. I update the code and get ot the result I want.
directoryParent = getSavePath caption: "SELECT THE PARENT DIRECTORY"
dirPath = directoryParent + "\*"
dirList = getDirectories dirPath
print dirList
for dir in dirList do(
assetsPath = dir + "\*.max"
assetsList = getFiles assetsPath
print assetsList
)
I am a newbie in PowerBi and currently working on a POC where I need to load data from a folder or directory. Before this load, I need to check if
1) the respective folder exists
2) the file under the folder is with.csv extension.
Ex. Let suppose we have a file '/MyDoc2004/myAction.csv'.
Here first we need to check if MyDoc2004 exists and then if myAction file is with.csv extension.
Is there any way we can do this using Power Query?
1. Check if the folder exists
You can apply Folder.Contents function with the absolute path of the folder, and handle the error returned when the folder does not exist with try ... otherwise ... syntax.
let
absoluteFolderPath = "C:/folder/that/may/not/exist",
folderContentsOrError = Folder.Contents(absoluteFolderPath),
alternativeResult = """" & absoluteFolderPath & """ is not a valid folder path",
result = try folderContentsOrError otherwise alternativeResult
in
result
2. Check if the file is with .csv extension
I'm not sure what output you are expecting.
Here is a way to get the content of the file by full path including ".csv", or return an alternative result if not found.
let
absoluteFilePath = "C:/the/path/myAction.csv",
fileContentsOrError = File.Contents(absoluteFilePath),
alternativeResult = """" & absoluteFilePath & """ is not a valid file path",
result = try fileContentsOrError otherwise alternativeResult
in
result
If this is not what you are looking for, please update the question with the expected output.
Hope it helps.
'Start Button' does the following:
Check the given folder path for .blf files
Copy all the existing .blf files to the destination folder
Show the directory of the folder in text file i,e. where the files are being created
Show the directory where the existing files are being copied i,e. Onto the server
Delete the file from parent folder after copying
How can i do the Point 5..where am i at fault?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
'Show the parent folder path
TextBox1.Text = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
' Show the destination folder path
TextBox2.Text = DestinationDirectory
For Each FileName As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
ListBox1.Items.Clear()
ListBox1.Items.Add(FileName)
Next FileName
For Each FileName In As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
File.Delete(Path.GetFileName(FileName))
Next FileName
End Sub
I did that and got the result. It was more like a silly mistake.
Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
'Show the parent folder path
Const ParentDirectory As String = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
TextBox1.Text = ParentDirectory
' Show the destination folder path
TextBox2.Text = DestinationDirectory
ListBox1.Items.Clear()
For Each FileName As String In Directory.GetFiles(ParentDirectory, "*.blf")
File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
File.Delete(FileName)
ListBox1.Items.Add(FileName)
Next FileName
End Sub
Gradle war: rename files not working with regular expr.
war {
into "foo"
from ("hello/world") {
include "bar/config/*.xml"
// remove bar/ in the path
rename '(.*)/bar/config/(.*)', '$1/config/$2'
// tried
// rename 'bar/config/(.*)', 'config/$1'
}
}
Trying to rename
foo/bar/config/*.xml -> foo/config/*.xml
The entry path was not changed inside the war.
rename is operating on the file name, not the full path. To change the path you'll need access to a FileCopyDetails object. One way to do that is with filesMatching():
war {
from('hello/world') {
includeEmptyDirs = false
include 'bar/config/*.xml'
filesMatching('**/*.xml') {
it.path = it.path.replace('bar/', '')
}
}
}
Using RegExp to search a folder for file types held in an Array.
How can I show a fail if the folder contains more than one different file type but it is perfectly OK to have multiple of the same file type in the folder.
Here's my code:
var AllowedFileTypes = ["orf", "tif", "tiff", "jpg", "jpeg"];
var regex = new RegExp('.+\.(?:' + AllowedFileTypes.join('|')+ ')$','i');
fileList = inputFolder.getFiles(regex);
Thanks