Load file.q from path containing space character - kdb

How to load script file from a path containing spaces?
For example, this works:
\l F:/file.q
Below attempts throw an error:
\l F:/Folder with spaces/file.q
\l "F:/Folder with spaces/file.q"
\l hsym `$"F:/Folder with spaces/file.q"
system "l "F:/Folder with spaces/file.q""

Not exactly practical, but if you need to load files with spaces in the path, you can use windows short file names:
So given a script path: F://Folder with spaces/file with spaces.q
Given
Folder with spaces gets shortname folder~1
script with spaces.q gets shortname filewi~.q
You can load the file as follows in q:
q)system "l F://folder~1/filewi~1.q"
Hello from a q script with spaces in file name
You can get the short name of a file/folder by listing the directory in command print with /x flag (eg. dir /x)
As in general with this situation in windows, you're likely better off avoiding spaces in a filepath.

I know this is a very old post, but just had the same issue. Found a solution that works for me:
system "cd c:/your path/with spaces/"
system "l your_script.q"

Related

How do I get a list of files in a directory in KDB?

I've got a directory of CSV files.
I can do:
\ls /home/chris/data/
which works, producing a list:
"AAA.csv"
"AAAU.csv"
"AABA.csv"
etc.
However, when I try to assign it, so I can actually do something useful with it:
files: \ls /home/chris/data/
I'm unable to actually save the list.
What am I doing wrong?
You can use the system keyword, \ only works if it's the first character on a line:
files: system "ls /home/chris/data/"
Alternatively, key can be used, which I prefer as it's platform-independent with respect to path separators, and the shell command for listing files:
key `:/home/chris/data

No such file or directory when we define the path as '~/path/to/csv' in postgres

lease=# COPY dhcpd_data (ip_address, start_time, end_time, mac_address, machine_name) FROM '~/outputcsvre.csv' DELIMITER ',' CSV HEADER;
ERROR: could not open file "~/outputcsvre.csv" for reading: No such file or directory
if i define the path as '/home/rihiraj12/outputcsvre.csv', it works fine.
Yes, that's normal.
You don't really have a directory called ~. When you execute a command on the command line, the shell will expand ~ to /home/rihiraj12 before running the program. But here you're not using the shell, so ~ is interpreted literally.
As a workaround you could say
COPY dhcpd_data (...) FROM PROGRAM 'cat ~/outputcsvre.csv' ...
But note that the COPY command is executed by the server, so this will make the server spawn a cat command and use the home directory of the PostgreSQL server.
To specify the file from your own point of view, you can (in psql) use the \copy meta-command (which has the same syntax as COPY):
\copy dhcpd_data (...) FROM PROGRAM 'cat ~/outputcsvre.csv' ...
This will use your own home directory as ~.
~ is a shortcut that unix-like shells can expand to be the home directory of your user.
i.e. if you use ~/outputcsvre.csv , the shell converts this to /home/rihiraj12/outputcsvre.csv before doing anything else with it.
Outside a shell, applications rarely implement this expansion - and neither does postgresql, so you have to provide real path to the file.
In the case of the COPY command in postgresql, it is executed by the server - so in this case you will have to provide a filename that the server can resolve and read directly. (i.e. a relative path would be relative to wherever the postgresql server is located - so use an absolute path for the file.)

Folder name with space issue

How do I handle a folder name containing spaces in Perl? For example C:\Sample Picture\Data.
I wrote this
use File::Glob ':glob';
$indir = "C:\\Sample Picture\\Data\\";
#flist = bsd_glob( $indir.'*');
This is throwing an error
The syntax of the command is incorrect.
The error message The syntax of the command is incorrect comes from the Windows command line, not from Perl
The issue is not to do with File::Glob, but with whatever you are doing with the contents of #flist. It's my guess that you're using backticks or system to rename one or more of the files or directories. This will fail if you use paths that contain spaces without enclosing the complete path in double quotes
If you need any more help then you must show the relevant part of your code

Postgresql cannot find file name specified in copy command

I try this:
COPY gemeenten
FROM 'D:\CBS_woningcijfers_2014.csv'
DELIMITER ';' CSV
and get this:
ERROR: could not open file "D:\CBS_woningcijfers_2014.csv" for reading: No such file or directory
I doubled the backslashes, tried an E string, replaced \ by /, used " instead of ' but now I've run out of options. I am sure the file exists. Anybody any idea?
If the file and the PostgreSQL database are on the same machine, then the path and/or name of the file are not correct.
If the file is on your local machine and the database is on another, you cannot use the COPY command in SQL. You have two main choices to make this work:
1) Use psql \copy from your local machine. The syntax is similar, but it will transfer from your local to the remote. The docs are pretty helpful: https://www.postgresql.org/docs/9.5/static/app-psql.html#APP-PSQL-META-COMMANDS-COPY
2) Upload the file to the remote machine and then execute your command. Just make sure you are referencing the correct path and filename.

How to copy folder (Via Command prompt) which is contain a space in the name?

if i copy without space (Name Folder),
example:
xcopy /E C:\Test\SQL G:\SQL
this copy all content of my folder, Fine!
i dont know how to copy folder if name contain a space, With "xcopy" command.
i found many reviews about space in command prompt and show me solutions like
c:\>xcopy /E "c:\Documents\SQL Server Management\" "G:\SQL\"
but doesn't work for me.
if I copy a folder where the name contains spaces, the result is: Invalid number of parameters...
Any can help me ?
Tnhks
You should report the error message you are receiving, what happened when you executed he command (if anything) and what you expected to happen.
Your problem is that copy requires a filemask to know which files you require to be copied.
c:>xcopy /E "c:\Documents\SQL Server Management*.*" "G:\SQL\"
specifies that all files with all extensions be copied. The quotes are required to specify "paths\containing spaces" as xcopy (or any other command has no way of reading your mind and can't be certain of what c:\Documents\SQL Server Management\ G:\SQL\ means - is it 'copy c:\Documents\SQL to "Server Management\ G:\SQL\"' or 'copy "c:\Documents\SQL Server" to "Management\ G:\SQL\"' or are sume of what appear to be arguments strays data or what?