I'd like to ask if its possible for 4D to create a document on a network directory. For example:
vIP:="\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\storage\"
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
one way to do this is:
you can map your second machine's drive to machine where your 4d database is running.
then this drive would behave like a local drive.
for example:
i have mapped a drive which is named as "D" drive on remote machine, and it becomes "W" drive on machine where 4D database is running.
then you can use this code
c_Text(vPath)
vPath:="W:\var\www....." //temp path.....
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
I know this is an old question, but there aren't too many of us 4D coders floating around here, so I'll answer this for posterity!
Yes, you can create a document on a network share like this, assuming you have the appropriate permissions to do so.
In this case, I think you just need to be careful of how you escape the path. Ensure that you're doubling up your backslashes so that the code block looks like this (note the extra backslashes around the IP address and folder name):
vIP:="\\\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\\storage\\"
vDoc:=Create document(vPath+"notes.txt")
If (OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Hope this helps!
Yes, although undocumented, the CREATE DOCUMENT command does works with a valid UNC path provided that you have sufficient privileges to create a document at the path given.
However, you have an issue with your sample code. Your issue comes down to your usage of the backslash \ character.
The backslash \ character is used for escape sequences in 4D and is therefore used for escaping many other characters, so it must also be escaped itself. Simply doubling all of your backslashes in your sample code from \ to \\ should correct the issue.
Your sample code:
vIP:="\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\storage\"
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Should be written like this:
vIP:="\\\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\\storage\\"
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Your code could be further improved by using Test Path Name to confirm the path is valid, and that the file does not exist. Then if it does exist you could even use Open Document and Set Document Position to append to the document, like this:
vIP:="\\\\100.100.100.100"
vPath:=vIP+"\\storage\\"
vDocPath:=vPath+"notes.txt"
If (Test path name(vPath)=Is a folder)
// is a valid path
If (Not(Test path name(vDocPath)=Is a document))
// document does not exist
vDoc:=Create document(vDocPath)
If (OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Else
// file already exists at location!
vDoc:=Open document(vDocPath)
If (OK=1)
SET DOCUMENT POSITION(vDoc;0;2) // position 0 bytes from EOF
SEND PACKET(vDoc;"\rHello Again World") // new line prior to Hello
CLOSE DOCUMENT(vDoc)
End if
End if
Else
// path is not valid!
ALERT(vPath+" is invalid")
End if
Related
I am working on TCL script that will open another tcl file and I want to get value of variable from second opened file and use it in the first file.
Two file abc.tcl and xyz.tcl
abc.tcl opens file xyz.tcl and reads value of variable and use it in abc.tcl.
If xyz.tcl sets a global variable, abc.tcl will be able to see it if it used source to load in xyz.tcl.
Here's a simple example. This is xyz.tcl:
set SomeVariable 12345
This is abc.tcl:
source xyz.tcl
puts "The password on my luggage is $SomeVariable"
The source command is really very simple internally. It just reads in the contents of the file (into a string), and then internally evals that string. Yes, this means that you probably shouldn't put source inside a procedure, at least not unless you're sure what the consequences of this are.
I have the following line of code:
file normalize [string map {\\ /} $file]
The string map operation is to make the line work for paths containing backslashes instead of forward (as is the case in Windows)
For some values of $file (let's say it's "/path/to/my/file") I get output similar to:
/path/to/"/path/to/my/file/"
This doesn't happen for all paths but I'm unable to figure out what causes it. There are no symbolic links in the path.
Is there something I'm doing wrong, or is there an alternative to file normalize that I could try?
my tcl version is 8.5
UPDATE:
On further investigation I see that the string map is not making any difference. The output of file normalize itself is coming with that extra text before the desired text. Also, the extra text seems to be from a previous run of the code.
UPDATE 2: It was because of the quotation marks in the input to file normalize
Most likely the path has backslashes where it shouldn't have them.
% file normalize {"/path/to/some/file"}
/path/to/"/path/to/some/file"
% file normalize \"/path/to/some/file\"
/path/to/"/path/to/some/file"
Perhaps some pathname handling code escaped special characters for some reason and left the path in a mangled state.
I would try to keep the pathname pristine and when it needs to be changed for display or other processing, make a copy of it first.
Here is a Ruby question guys. So need to parse through the html file and catch urls and emails can't come up with proper regex expression. Tried 100+ regexes and all the times I cash something else with the url.
File.open("/Desktop/file.html").each_line do |line|
if line.split("href=\"") =~ /???/
puts line
end
end
# I can use line.split("href=\"") so each new line will start with url =>
(https://www.facebook.com/students">
The question is what regex can I use to catch everything from https to the end of the url which ends with (") (there could be one or more samples of same url so {1,2} is needed
Try this
file = File.open('filename_path')
links = file.read().scan(/href=\"(?<url>.*?)\"/)
you get links in array
it also works if you remove ?<url> from above(it's just named capture group)
I have the output of recursive grep (actually ag) in a buffer, which is of the form filename:linenumber: ... [match] ..., and I want to be able to go to the occurrence (file and line number) currently under the cursor. This told me that I could execute normal-mode movements, so after extracting the file:line portion, I wrote this function:
function OpenFileNewTab(name)
let l:pair=split(a:name, ":")
execute "tabnew" get(l:pair, 0)
execute "normal!" get(l:pair, 1) . "G"
endfunction
It is supposed to open the specified file in a tab and then do <lineno>G, like I am able to do manually, to go to the specified line number. However, the cursor just stays on line 1. What am I doing wrong?
This question, by title alone, would be an exact duplicate, but it talks locating symbols in other files, while I already have the locations at hand.
Edit: My mappings for grep / ag are as follows:
nnoremap <Leader>ag :execute "new \| read !ag --literal -w" "<C-r><C-w>" g:repo \| :set filetype=c<CR>
nnoremap <Leader>gf ^v2t:"zy :execute OpenFileNewTab("<C-r>z")<CR>
To get my grep / ag results, I put the cursor on the word I want to search and enter <leader>ag, then, in the new buffer, I put the cursor on a line and enter <leader>gf - it selects from the start up to the second colon and calls OpenFileNewTab.
Edit 2: I'm on Cygwin, if it is of any importance - I doubt it.
Why don't you set &grepprg to call ag ?
" according to man ag
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
" And then (not tested)
nnoremap <Leader>ag :grep -w <c-r><c-w><cr>
As others have said in the comments, you are just trying to emulate what the quickfix windows already provides. And, we are lucky vim can call grep, and it has a variation point to let us specify which grep program we wish to use: 'grepprg'.
Use file-line plugin. Pressing Enter on a line in the quicklist will normally open that file; file-line will make any filename of the form file:line:column (and several other formats) to open file and position to line and column.
I only found this (old) thread after I posted the exact same question on vi.stackexchange: https://vi.stackexchange.com/q/39557/44764. To help anyone who comes looking, I post the best answer to my question below as an alternative to the answers already given.
The gF command, like gf, opens the file in a new tab but additionally it also positions the cursor on the line after the colon. (I note the OP defines <leader>gf so maybe vim/neovim didn't auto-define gf or gF at the time this thread was originally created.)
I have a file upload form and would like to use the filename on the server, however I notice that when I upload it the spaces are dropped. On the client/browser I can do something like this in an event called after the input type='file' element has changed:
function process_svg (e) {
var files = e.target.files || e.originalEvent.dataTransfer.files;
console.log(files[0].filename);
And if I upload a file with the name 'some file - type.ext' 'some file - type.ext' will be printed in the console. On the server (running bottle) however if I run:
#route('/some_route')
def some_route():
print(request.files['form_name_attr'].filename)
I get 'somefile-type.ext.' I am guessing this has to do with uri escaping (or lack there of), but since you cannot change a file preupload how do you get around this and preserve it? Strangely I cannot find mention of this on google, in part I have had trouble thinking of appropriate search terms, but I'm also aware that this may not actually be native behaviour, but a bug elsewhere in my code.
I do not think that is the case as I've issued these console.log and print statements at the end (right before the upload) and beginning (right when the server starts processing the request) and do not believe I really have any code to touch it in between, however if that is the case please let me know as I could be looking in the wrong direction.
You want raw_filename, not filename.
(Note that it may contain unsafe characters.)
#route('/some_route', method='POST')
def some_route():
print(request.files['form_name_attr'].filename) # "cleaned" file name
print(request.files['form_name_attr'].raw_filename) # unmodified file name
Found this in the source code for FileUpload.filename:
Only ASCII letters, digits, dashes, underscores and dots are allowed
in the final filename. Accents are removed, if possible. Whitespace is
replaced by a single dash. Leading or tailing dots or dashes are
removed. The filename is limited to 255 characters.