Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to parse a txt file and I want to reference it relative to my current directory location. If I put the file path in completely it will work but it I try to use
..\src\test.txt it wont find it. Is this not the proper way to reference a file relative up one directory?
Any help would be appreciated
If you put "..\src\test.txt" in a string constant, you need to double all the backslashes so that "\t" and "\s" are not interpreted as escape sequences. (Or you can use forward slashes instead, which is more portable.)
It will depend on what the current working directory is set to. By default it is the directory the executable resides in if you double-click the app from Explorer, or the current path the shell is in if started from a command prompt.
If test.txt is in c:\code\app\src and your application is in c:\code\app, the relative path "..\src\test.txt" is going to end up c:\code\src\test.txt (if launched from explorer).
Try printing the output of _getcwd before you try opening the file to verify what directory is the current working directory.
Assuming that your directory structure looks like:
project
+---src
| test.txt
| proj.c
\---bin
a.out <- Working directory
your relative path is correct; your working directory is actually on the same level as the text file.
If you really mean that the file is up one directory as you stated, like this: (Note: This is an awkward project structure)
project
\---src
| test.txt
| proj.c
\---bin
a.out
or like this: (makes more sense)
project
| test.txt
+---src
| proj.c
\---bin
a.out
Then the path you need is "../test.txt" or, equivalently, "../../project/test.txt"
A better location would be in a data directory, so your path would be "../data/test.txt"
I guess this is a windows VS vbuild (given the back slashed path)
VS will have put the binary in something like project\bin\debug. And when you run it in VS it will set the current WD to the location of the binary.
so
a) copy the file to the right place
b) change the project properties debug setup to say set the current path to the place where you expect the file to be (relatively)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When trying to download a file from my GitHub repository using CURL, it always downloads it correctly with all the content fine, except that it uses LF instead of CRLF, which is what I need for windows. This is used for being able to update a batch file automatically, and it worked fine, except this one specific file. This is the file that causes problems (GitHub). When pushing this file from GitHub desktop, I made sure that it was saved as CRLF, but seems like it's somehow ignoring it.
Note: This also happened when using the BITSADMIN tool.
Thank you.
Have a try with changing your usage to include the -B --Use-ASCII option like so:
curl -s -B --Use-ASCII https://raw.githubusercontent.com/L89David/DarviLStuff/master/versions > "!temp!"
It does still appear though that in the first script you haven't terminatinated the last line with a {CR}{LF}
A small tip with importing variables like this, If you change the stored format to:
Set "echoc=59"
Set "pbar=27"
Set "virint=31"
And the file type to bat or cmd, You can easily import them by just calling the file once it's downloaded.
This question already has answers here:
Terminal - command not found
(2 answers)
Closed 3 years ago.
I have a .sh file in bin folder, but when I try to use it, the server cannot find it in the folder.
/home/monju/full/app/bin $ls
checkServer.sh etf_disagg_config_loader.sh getLogName.sh mapr
common.sh findLog.sh jgrouplog.sh phase2b
commonStart.sh findServer.sh jmx postInstallSetup.sh
errorLog.ksh followLog.sh jrebel.sh probe.sh
etf genTestFile.ksh killServer.sh RMSDisable.sh
/home/monju/full/app/bin $stopServer.sh
bash: stopServer.sh: command not found
while when I use /home/monju/full/app/bin/stopServer.sh, it can be used.
Just because it's in a directory named bin doesn't mean the shell can magically find it.
You need to put the full path in your $PATH environment variable, or symlink it to somewhere that's in the $PATH already.
Of course, if you only want to run it from the current directory, it's best to use
$ ./stopServer.sh
Which is the same as the long absolute path you gave, only using relative path syntax where . means current directory.
Putting . itself in $PATH is considered bad practice.
Use
./stopServer.sh
and make sure you have execution rights.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a file that I have downloaded from Google (it is inside the download folder)
and I want to move it to the autorun folder ( The folder where files run when the computer turns on).
I need to move the file using a cmd command ( the reason why is that it's going to be done using the USB rubber ducky.
I am using windows 10 64 bit if it is any help.
The path where the file is
C:\Users\%USERPROFILE%\Downloads\Test.exe
and the path I want to move it to is
C:\Users\%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
The reason why %USERPROFILE% is that it should work on all computer.
To move a file, you use the move command.
move "%USERPROFILE%\Downloads\Test.exe" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
I put quotes around the source and target in case you're one of those people who has spaces in their username for some reason (and the target needs them anyway for the spaces in "Start Menu").
From the output of move /?:
Moves files and renames files and directories.
To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.
/Y Suppresses prompting to confirm you want to
overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.
To move file use mv, but not working if you don't do with admin, how you can hack, try superuser tools for windows!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I would like to write a bat script to do the following:
Use 7 Zip to extract files from an existing zip file, into a folder by the same name as the original zip file (bar the .zip extension), and keeping the file & directory structure that was contained in the zip file.
I can extract all the same files into the current directory, by using
"C:\Program Files (x86)\7-Zip\7z.exe" e myZipFile.zip
Reading the help of the 7z-command by just typing "C:\Path To\7-Zip\7z.exe" gets the help with all possible arguments. Here we find the following interesting ones:
e : Extract files from archive (without using directory names)
and
x : eXtract files with full paths
Trial and error shows that the latter is the one fitting your desired behaviour without bigger effort :)
After the comment by #BadmintonCat here is the addition that will create a folder to zip everything into (use as batch script with the file as argument):
#echo off
SET "filename=%~1"
SET dirName=%filename:~0,-4%
7z x -o"%dirName%" "%filename%"
From the help: -o{Directory} : set Output directory. 7z will create the directory if it does not already exist.
Just use the command: 7z x *.zip -o\*
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Every time I compile a C program, say with the cc compiler, I get an executable in the current directory. Now if I want to run it, instead of typing out just a.out or name_of_executable, I have to prefix that with this combination ./a.out.
I understand the meaning behind . (link to the current directory) and .. (link to its parent directory), also that / is a separator between directory names.
But what is the meaning of ./? Is it just a formal way to separate between referring to a name of something, and the intention to run that something (because you can't have / in your filename)?
When you type the name of an executable program, the shell searches for it in a sequence of directories whose names are stored in the $PATH environment variable.
The current directory, ., normally isn't (and shouldn't be) in your $PATH. So if you type just a.out, the shell won't find it -- unless there happens to be a /usr/bin/a.out, or /usr/local/bin/a.out, or ....
Why shouldn't . be in your $PATH? (Sometimes, on some systems, it is.) Because it creates a security hole. If . is at the front of your $PATH, then if you cd to a directory that happens to contain a command called ls, it's very easy to execute it accidentally, with arbitrarily bad consequences. Even if . is at the end of $PATH, you can still run into problems if the little program you just compiled, or the script you just wrote, happens to have the same name as a standard command. I've seen a lot of people becoming very confused because the named a test program test, but typing test runs /bin/test.
A command can be either a built-in command (provided by the shell) or the name of an executable file. If you type ls, the shell finds an executable file called ls in one of the directories named in your $PATH. If you type a.out, there is no executable file of that name in any of the directories named in $PATH -- thus the error message.
Typing a path to the executable file (even a relative path like ./a.out) causes the shell to bypass the $PATH search; you're telling the shell exactly where to find the executable file rather than asking the shell to search for it.
For security reasons, most UNIX's don't allow running a program from the current directory, only from your PATH variable. Imagine if you un-tarred a file that contained a command such as ls or gcc and it had a trojan horse installed? You could easily run it on accident.
Therefore, you have to use ./ to specify you want to run a command from the current directory.
When you enter a name of the executable, UNIX appends the name to elements of the PATH variable to obtain the path to the executable. The current directory is not searched by default. When you prefix ./ to the name, you instruct the shell to look for the executable in the current directory denoted by a dot .
Note that you could add the current directory to the PATH in order to avoid typing ./ prefix, but this is not recommended.