How to use the path with the space in docker file - dockerfile

I want to write a cmd in docker file to copy the file at the destination C:\windows\Program Files. I am having an issue due to space in program files. I am able to copy the file to different location. Any suggestion will be appreciated.
I am getting below error:
Step 4 : COPY "C:\docker\prerequisites\MicrosoftSDKs" "C:\Program Files
(x86)\MicrosoftSDKs"
Forbidden path outside the build context: C:\docker\prerequisites\MicrosoftSDKs
()

Use the JSON form, you have to use double backslashes inside the braces
FROM microsoft/windowsservercore
COPY ["C:\\docker\\prerequisites\\MicrosoftSDKs", "C:\\Program Files (x86)\\MicrosoftSDKs"]
You can also use slash:
COPY ["C:/Program Files/nodejs", "/windows/system32"]

workaround:
write the script with the spaces into a file, and in the docker file, run the script by calling the file.
in a file named myscript.bat write
COPY "C:\docker\prerequisites\MicrosoftSDKs" "C:\Program Files (x86)\MicrosoftSDKs"
and in the DockerFile
RUN myscript.bat

You can use ARG:
ARG sourc = "C:\docker\prerequisites\MicrosoftSDKs"
ARG destination = "C:\Program Files (x86)\MicrosoftSDKs"
COPY ${sourc} ${destination}

Enclosing the path in quotes like this should help if there are spaces:
"C:\windows\Program Files"

Related

Is there a way to copy a directory full of files and change their file extentions in a Dockerfile

Problem
I want to copy all the files in a directory over to my container, changing the extension.
Setup
Lets say I want my local directory src/* copied into the container at /work/
src/ contains a bunch of files with extensions like .txt.
I want to COPY them over and change their extensions to .textfile.
Currently I am doing
COPY src/file1.txt /work/file1.textfile
COPY src/file2.txt /work/file2.textfile
COPY src/file3.txt /work/file3.textfile
...
This works file but create a bunch of layers in my image and I'd like to just have it done in one step.
What I've tried
COPY src/*.text /work/*.textfile
This doesn't work.
Work around
I installed util-linux and used the rename command like so:
COPY src/*.txt /work/
RUN rename '.txt' '.textfile' /work
But this is undesirable as the command comes as a package.
Question
Is there a way to do this simply as a dockerfile command?

c++ copying directory into an another directory (linux cp command)

I'm trying to implement cp -r command so that when user types in cp -r dir dir1, dir gets copied and pasted inside dir1. Below is what i have so far and it does copy the files and directories inside the directory, but it doesn't copy directory itself. For example, when there is a file1 and a directory 'a'inside dir then it will only copy and paste file1 and 'a' inside of dir1, but not the directory dir itself.
Any suggestions?
You start your algorithm one step too deep into the directory you are copying: dir_entry = readdir(dir) reads all the entrys inside your source directory and therefore the source directory itself is not copied.
The function is fine, you just need one extra step before you call it.
Instead of calling dirCopy("a", "b") you need to start by executing
mkdir("b/a", convertMode("a"));
and then
dirCopy("a", "b/a");
So you are going to need code that extracts the last filename part from your path so you can then append it to newPath. If you need assistance for that you can look at this question: Get a file name from a path

Extract file with 7Zlib command line into directory

I would like to extract a file with 7za.exe (Link to download 7za.exe command line).
I can extract with the commands e or x, but my files are extracted in the current file.
It is a mess, that is why I want to specify the destination directory.
I already tried this command but it won't work :
7za e myZipFile.zip myDestinationFolder
7za x myZipFile.zip myDestinationFolder
It says No files to process
Finally I've just find the way to extract my zipped files in another folder !
By default 7z extract files into the current folder...
This allow to extract the files in the c:\soft folder :
7z e archive.zip -oc:\soft *.cpp -r
The trick is that we have to attache the command -o directly before our destination directory ! So beware : no space between the command -o and our destination directory path.

urllib.urlretrieve creates file on disk

I do this:
thing = urllib.urlretrieve(url, "somefile.jpg")
It works, it gets the file, but it actually creates a file on the file system in the cwd. I write the file a little later to an appropriate path, but I don't want the file in the cwd at that time. What can I do?
Windows 10
If you want the file to go in a different directory, simply specify a path to where you want the file to go.
If you don't want the file to still be in the cwd after copying it, then delete the copy you don't want.
If you don't want to create a file at all, use something like urlopen.
There's a couple solutions 1. Change the cwd or 2. specify an alternate directory (as suggested by Scott Hunter), to do these:
1. Change your cwd (current working directory):
os.chdir("/Users/Desktop/SpecificDirectory/")
-now try your script.
OR
2. Specify an alternate directory in the download urllib command:
`thing = urllib.urlretrieve(url,"/Users/Desktop/SpecificDirectory/somefile.jpg")`

Xcode 4 file input/output, command line tool C++

I'm trying to figure out where to save multiple .txt files so that i can have a command line tool project in Xcode read directly in from them while running it.
I understand that Xcode compiles everything to a folder, DerivedData, which i have saved in the same location as my source code for each project respectively.
can i save multiple .txt files anywhere in the DerivedData folder or include it in the build settings and phases so that when i run the command line tool i can type the name of a file, it will read in from that file.
By default the compiled/linked binary will look into its own directory for files.
For example, my binaries are at ProjectName/Build/Products/Debug/ and therefore it will look for files from that dir.
You can use relative path from that folder to the outside.
Or, you can create a symbolic link to another directory (on Terminal):
ln -s source_dir target_file
target_file must be located in the same directory as your binary. And you can reference the other files like "target_file/file1.txt", etc.