Questions tagged [getcwd]

The getcwd() function retrieves the current working directory pathname on POSIX compliant machines.

The function getcwd() is available on Unix machines to copy the current working directory (as an absolute pathname) to a supplied buffer of an array of characters of a given length. It is specified in POSIX.1-2001 to have the following signature:

char *getcwd(char *buffer, size_t size);
104 questions
1
vote
2 answers

PHP if/else is not functioning properly

I am trying to use an if/else statement in PHP. Currently what I am trying to do is if the $_SESSION['usr']; is equal to the current directory ($dir_auth2) variable that the user is trying to access. Then they can access the directory or index.php I…
aidangig
  • 199
  • 1
  • 12
1
vote
2 answers

Incorrect path with function getcwd()

I get the wrong path back. The Datafile is in D:... and get everytime the path C:\Python27\lib\site-packages\xy back from python. I use the function path = getcwd() How can I fix it?
A.Boss
  • 217
  • 1
  • 5
  • 9
1
vote
3 answers

What could change the directory in php Windows besides chdir() and chroot()? (Simpletest include file bug in Windows)

(Sorry if this is titled poorly. I'm actually trying to accomplish two things - find out how the current directory can get changed in PHP, and fix a bug in Simpletest running on WAMP.) I'm running SimpleTest (simpletest.org) on my Windows 7 local…
Burton Kent
  • 808
  • 7
  • 12
1
vote
2 answers

getcwd for current location based on ftp account permission

I'm trying to make a small script that's changing the permission for specific file using a ftp connection. My problem is the absolute path. I have a ftp account wich land on the script directory (/script/). If i'm using getcwd, it will return the…
John Doe
  • 23
  • 4
1
vote
2 answers

non-standard / non-POSIX getcwd() not calling malloc

What part of this quote from the getcwd man-page am I misunderstanding? char *getcwd(char *buf, size_t size); ... As an extension to the POSIX.1-2001 standard, Linux (libc4, libc5, glibc) getcwd() allocates the buffer dynamically…
Kdawg
  • 167
  • 11
1
vote
4 answers

Using malloc properly

I'm trying to put my directory pathname on a string variable, like this: int main(int ac, char **av) { char*dir; if(ac > 2) { dir = malloc(sizeof(*dir) * 512); getcwd(dir, sizeof(*dir)); printf("dat dir is:\n"); …
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
1
vote
2 answers

cwd and gwtcwd returns a linux style path on windows

If I run this script: use Cwd; print "$^O\n"; print cwd; The output is: C:\tmp>perl tmp.pl msys /c/tmp How can I get windows style path C:\tmp?
Pawel P.
  • 3,731
  • 4
  • 20
  • 20
1
vote
4 answers

Get URL of a file on a server with PHP

Say I want to find a file in one of the parent directories of the script. Consider this file tree: Folder0 Folder1 needle.php Folder2 Folder3 script.php I'm running script.php and I need to find which…
Stas Bichenko
  • 13,013
  • 8
  • 45
  • 83
1
vote
4 answers

getcwd() returns NULL after new pointer is created

I've just started learning linux and C, please don't judge me strictly. I'm trying to find a current working directory and to open file in this directory to find a specific word. It gives correct cwd if I find only cwd, but when I added while loop…
Nazerke
  • 2,098
  • 7
  • 37
  • 57
0
votes
3 answers

Do I need to use substr() to bring up a directory or can I another code?

Everything in this file is set up in a way in which $_GET['q'] brings up the main domain name and the other directories in the website are brought up in this manner: else if (substr($_GET['q'], 0, 7) == 'quotes/') If I wanted to have a folder…
Vbena
  • 1
  • 1
0
votes
1 answer

Execve cd /bin pwd [C]

I am currently writing a shell in C (school project). My cd and pwd is working. But when I do: cd /bin and after pwd, pwd shows /usr/bin. For me it looks like execve with pwd can't handle /bin but why? name% ./myshell name: cd Current working dir:…
niki
  • 23
  • 7
0
votes
0 answers

Add a ".csv" extension to a file's name or path

Is there a recommended way to add a ".csv" extension, to a file's name or path, which you want to export as a csv? I achieved it directly and naively, and I wonder if there is another way to make it more elegant. My code: def get_file_path…
Amit S
  • 225
  • 6
  • 16
0
votes
1 answer

os.getcwd() raise Exception with django dev server

I have a django project running inside docker, and the service is up with the command of python manage.py runserver, with file autoreload open, and using threadings. My code invokes shutil.make_archive() which will then invoke os.getcwd(), and from…
always_beta
  • 229
  • 4
  • 10
0
votes
2 answers

Does getcwd() ignore the size of the buffer and copy it?

#include #include #include int main() { char wd[10]; if(getcwd(wd,BUFSIZ) == NULL){ //BUFSIZ = 8192 perror("getcwd"); exit(1); } printf("wd = %s\n",wd); } This C code…
0
votes
0 answers

getcwd() is faulty when in a programmed launched by abspath

Error When an alias of python command runs on a file defined with an absolute path, its getcwd() becomes faulty, i.e. it doesn't represent my current location from which I'm running this script. Reproduce Add the following two lines to ~/.bashrc cd…
ysig
  • 447
  • 4
  • 18