I am using an Excel macro to call up UltraEdit in order to execute a script on some files.
In the Excel macro I write the path that I want the new file to be saved in by the UltraEdit script. Up until this point all work and if I do a write of the value I read in the temporary file I see that I have the correct path.
But when I use the saveAs("^c") the file does not get saved to the path I specified, but instead gets saved to the current directory.
If I use the following code it saves the file properly. But I don't want to hard code the path:
var sPath="H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\"
+ sTransSet
+"_"
+ sDocNum
+ "_"
+ now.getFullYear()
+ month
+ day
+ "-"
+ hours
+ minutes
+ seconds
+ ".txt";
UltraEdit.saveAs(sPath);
This is the code I am trying to fix:
UltraEdit.selectClipboard(1); // switch to user clipboard #1
var sPath=asParameterList[0]
+ sTransSet
+"_"
+ sDocNum
+ "_"
+ now.getFullYear()
+ month
+ day
+ "-"
+ hours
+ minutes
+ seconds
+ ".txt";
UltraEdit.clipboardContent=sPath;
UltraEdit.outputWindow.write("sPath Value After assign= "+sPath);
UltraEdit.saveAs("^c");
The write command shows me the following:
sPath Value After assign=
H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\856_IPEX-155630-2_20190607-152606.txt
Instead of saving the file to directory
H:\\IPEX\\DataFiles\\IPEX_Originals_Cleaned_Files\\
it saves the file to directory
H:\IPEX\DataFiles\Boomi_IPEX_Files
which is the directory of the original file.
I agree with Alexander Pavlov and his analysis of the cause of the issue. The full qualified file name in clipboard is invalid because of having leading newline characters.
And the full qualified file name string contains additionally \\ instead of just \ as directory separator. \\ within a file path is no problem for Windows file system kernel functions in comparison to the newline character which is an invalid character for a file name or path according to Microsoft's documentation Naming Files, Paths, and Namespaces. But the full qualified file name should be nevertheless 100% correct.
These issues should be best fixed in Visual Basic macro in Excel file. In Visual Basic strings the backslash character is not an escape character like in other programming and scripting languages. Therefore the file path must be defined in Visual Basic macro with just \ and not with \\. And leading spaces/tabs/newline characters should be also removed from file path string in Excel macro before copying the full qualified file name to clipboard.
It is of course also possible to use in UltraEdit script following line before saving the new file with full qualified name in clipboard.
UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/^\s+/,"").replace(/\\\\/g,"\\");
The first replace removes all leading whitespaces according to Unicode definition and the second replace modifies all occurrences of \\ to just \ in file name string before the fixed full qualified file name is copied back to clipboard.
But there is really no need to use a clipboard as also written by Alexander Pavlov. The invalid full qualified file name string is already stored in a JavaScript String object with the not really good name sPath. A better name for this string variable would be sFullFileName. The UltraEdit function UltraEdit.saveAs() expects a String object as parameter. So it is also possible to use in UltraEdit script:
var sFullFileName = sPath.replace(/^\s+/,"").replace(/\\\\/g,"\\");
UltraEdit.saveAs(sFullFileName);
Note: Replacing all occurrences of \\ by just \ would be wrong for full qualified file name having a UNC path which must start with two backslashes.
Your debug output prints file name on a new line. It seems filename is preceded with a new line symbol. I think it is why it does not work. Try to trim all spaces and new lines from sPath up until the first character.
Related
h
words_to_guess= (which code should I enter here in order to import words from a text file )
my text file is names word.txt so i tried
words_to_guess =import words.txt
You can assign the content of a .txt file to a variable using this code:
words_to_guess = open("words.txt")
Just make sure that the file "words.txt" is in the same directory as the .py file (or if you're compiling it to a .exe, the same directory as the .exe file)
I would also like to point out that based on the screenshot you provided, it looks like you're trying to get a random word from the .txt file. Once you've done the above code, I would recommend adding this code below it as well:
words_to_guess = words_to_guess.split()
This will take the content of "words_to_guess" and split every word into a list that can be further accessed. You can then call:
word = random.choice(words_to_guess)
And it will select a random element from the array into the "word" variable, hence providing you a random word from the .txt file.
Just note that in the split() function, a word is determined by the spaces in between, so if you have a word like "Halloween Pumpkin" or "American Flag", the split() function would make each individual word an element, so it would be transferred into ["Halloween", "Pumpkin"] or ["American", "Flag"].
That's all!
I'm trying to print a filepath in Rmd as part of a log. The path is passed to the R markdown file, so it comes in as a character string. \ is a special character for both R and LaTeX, which is used to render the final document. Currently, the file paths use \ so that they can be used in the parent R function to actually load the files. What do I need to replace this with in order to actually print it to the pdf?
Replace it by / or \\\\ - the latter one "escapes" the backslash actually twice.
i'm trying to upload file to specific non-existing path on Microsoft Sharepoint Group assuming folder hierarchy will be created based on that path. And that's true.
Problem appears when path segment have special characters. I found MS documentation stating that path segment should be encoded (using escape function in Javascript).
So let's say i'm uploading file File1.txt to a path Test 1/Whatever%Text!Here
Here's what url would look like:
PUT https://graph.microsoft.com/v1.0/groups/<group-id>/drive/items/root:/Test%201/Whatever%25Text%21Here:/children/File1.txt/content
You can see encoded path segment (/Test%201/Whatever%25Text%21Here) and how % is encoded to %25. Seems fine to me. But this URL will create subfolder called Whatever%25Text!Here, not Whatever%Text!Here
%25 stays %25, it's not decoded to %. Does anyone have a clue what's going on?
I was mainly testing through Microsoft Graph Api explorer, trying several different URLs, like % changing to %2525 but without luck.
The % symbol is one of OneDrive for Business' "Reserved Characters".
From the documentation:
OneDrive reserved characters
The following characters are OneDrive reserved characters, and can't be used in OneDrive folder and file names.
onedrive-reserved = "/" / "\" / "*" / "<" / ">" / "?" / ":" / "|"
onedrive-business-reserved = "/" / "\" / "*" / "<" / ">" / "?" / ":" / "|" / "#" / "%"
I've come across the following code and can not understand what operation the double exclamation marks provide. This code-snipet is from a FAKE script used in a CICD system. Microsoft's Symbol and Operator Reference does not list this operator, nor can I find it in FAKE's API Reference.
!! (projectPackagePath + "/*.zip")
|> Seq.iter(fun path ->
trace ("Removing " + path)
ShellExec tfCommand ("delete " + path + " /noprompt")
Another example of usage
let buildLabelFiles =
!!(labelPath ## "*.txt")
The !! operator takes a file pattern and returns a collection of files matching the pattern.
For example, if you want to print all text files in the current folder, you can write:
for file in !! "*.txt" do
printfn "%s" file
If you look at the operator definition in the source code, you can see that it is just an alias for creating a IGlobbingPattern value (see the type definition) that includes files given by the specified pattern. The IGlobbingPattern type implements IEnumerable, so you can iterate over the files, but you can do a couple of other things with IGlobbingPattern such as combining two file sets using ++ or removing some files from a file set using --.
I am following instructions from this link on how to append Stata files via a foreach loop. I think that it's pretty straightforward.
However, when I try to refer to each f in datafiles in my foreach loop, I receive the error:
invalid `
I've set my working directory and the data is in a subfolder called csvfiles. I am trying to call each file f in the csvfiles subfolder using my local macro datafiles and then append each file to an aggregate Stata dataset called data.dta.
I've included the code from my do file below:
clear
local datafiles: dir "csvfiles" files "*.csv"
foreach f of local datafiles {
preserve
insheet using “csvfiles\`f'”, clear
** add syntax here to run on each file**
save temp, replace
restore
append using temp
}
rm temp
save data.dta, replace
The backslash character has meaning to Stata: it will prevent the interpretation of any following character that has a special meaning to Stata, in particular the left single quote character
`
will not be interpreted as indicating a reference to a macro.
But all is not lost: Stata will allow you to use the forward slash character in path names on any operating system, and on Windows will take care of doing what must be done to appease Windows. Replacing your insheet command with
insheet using “csvfiles/`f'”, clear
should solve your problem.
Note that the instructions you linked to do exactly that; some of the code includes backslashes in path names, but where a macro is included, forward slashes are used instead.