I want to put output information of my program to a folder. if given folder does not exist, then the program should create a new folder with folder name as given in the program. Is this possible? If yes, please let me know how.  Suppose I have given folder path like "C:\Program Files\alex" and alex folder doesn't exist then program should create alex folder and should put output information in the alex folder.
2402
What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:  import os  file_path = "/my/directory/filename.txt" directory = os.path.dirname(file_path)  try:     os.stat(directory) except:     os.mkdir(directory)         f = file(filename)   Somehow, I missed os.path.exists (thanks kanja, Blair, and Douglas). This is what I have now:  def ensure_dir(file_path):     directory = os.path.dirname(file_path)     if not os.path.exists(directory):         os.makedirs(directory)   Is there a flag for "open", that makes this happen automatically?
83242
If I do a command like (on windows cmd.exe):  where dir   or  where cd   I get the following message:  INFO: Could not find files for the given pattern(s).   This tends to mean to me that cd and dir are not actual programs, but are built in to cmd.exe.  Now the real question is:   Is there ant way to replace cd and dir with other programs?  If you wanted to replace say more, you could just put another program by that name in the system PATH in front of where more is.  But you cannot do that with cd and dir.  Am I just stuck with them?
66165
How do I get a list of all files in a folder, including all the files within all the subfolders and put the output in a file?
84085
I'm making a C program where I need to get the directory that the program is started from.  This program is written for UNIX computers. I've been looking at opendir() and telldir(), but telldir() returns a off_t (long int), so it really doesn't help me.   How can I get the current path in a string (char array)?
87039
I'm looking for a way to batch create a folder followed by sub-folders.  I'm looking at something like  c:\users\user\desktop\sample\1 c:\users\user\desktop\sample\2   etc.  Any ideas?  I'd prefer .cmd/PowerShell methods to do so.   If there's a way to do so via a terminal, I'll be happy to attempt any ideas/solutions by booting into a Linux live disc via usb.
104672
I'm seeking a way to create directory and change my present working directory to newly created directory just by using a single command. How can I do this?  i.e Instead of doing  user@Computer:~$ mkdir NewDirectory user@Computer:~$ cd NewDirectory user@Computer:~/NewDirectory$    I want to do  user@computer:~$ **command** NewDirectory user@Computer:~/NewDirectory$   What can the command be?
100638
As a simple example, I have a bunch of source code files. I want to store the "head" command output to a variable for all these files.  I tried:  output=$(head $file)   but what happened is that this automatically trimmed all \n characters when storing the output to a variable.  How do I store the command output as is without removing \n characters?
81218
I am trying to do a new environment or command (i tried both) where i can put in the name, description and code of a Method in c++ and it gives me a new section with the MethodName, the code listed and the description below. But i am not able to use the listings environment in a new command or new environment.. Consider my MWE   \documentclass[a4paper,11pt]{article} \usepackage{listings}  \newcommand{\method}[3] { \section{#1}\label{#1} \begin{lstlisting} #2 \end{lstlisting} #3 }   \begin{document}  \method{MethodName}{Method Void MethodName()}{Description of the Method blablabla}  \end{document}   How can I fix this?   I would prefer to do it using a macro since I don't need an ending.
27159
I am new in Linux so here is my very basic question. I have a directory with 41 folders. I need to create a loop so that the process goes into each folder, copy all the files and then paste everything in a specific folder.   Any idea how to approach this? It would be a lot of clicking without a code solution  In the image you can see all the folders I need to access and the output folder where I want to paste everything (zPASTE_EVERYTHING_HERE)    My path is: /shared/home/data/output  Would like to paste everything in: /shared/home/data/output/zPASTE_EVERYTHING_HERE
98998
I need to do create a file with a filename such as :&gt;?, is this possible somehow? Windows stops it.
91826
A friend with Windows 7 somehow managed to create a folder on her computer whose name ends with "...".  Normally, Windows won't let you create folders with names ending like that. I really don't know how she managed to do it.  The Windows Explorer doesn't suffer from it too much, as all files inside are accessible and can be manipulated normally. However, it's impossible to rename it or delete it. Worse, it's impossible to delete the parent folder as well.  It can't be reached through the command line as it says the file doesn't exist.  Anyone knows a way to fix that? I don't mind to blow it up as I can move files from and to it through the Explorer normally.
8107
How can you you insert a newline from your batch file output?  I want to do something like:  echo hello\nworld   Which would output:  hello world
36433
I'm wondering where a new path has to be added to the PATH environment variable. I know this can be accomplished by editing .bashrc (for example), but it's not clear how to do this.  This way:  export PATH=~/opt/bin:$PATH   or this?    export PATH=$PATH:~/opt/bin
95379
Is there a shell command for outputing absolute path for specified program? I'd like to know where executable binary file is.
88990
I created a folder on my home directory call junk, and let's say I want to move all .cpp and .h files to it. How would I do it? My first thought is to start with find ~ -name *.cpp -print, but I don't know how to put in multiple patterns into the find argument, and I'm fairly lost after that.
3991
Why in Windows, can't you name a folder 'con'?  Whenever I try to name a folder as "con" (without the quotes) it defaults to its original name.  Why does it do this?
44814
So I'm trying to run foo.exe, but I don't want the output to the terminal but into a file. Running foo.exe &gt; foo.txt should accomplish this for me, but it's not. When I'm running the exe-file, I get the output. The exe is working fine in other words. However, when I try to send the output to a file, the only thing I get is this:  'c:/Program' is not recognized as an internal or external command, operable program or batch file.   This only shows up when I try to send it to a file. Thinking that it could be the path (which is c:\Program Files (x86)\ and so on) which is misinterpreted, I tried specifying the output file like so: foo.exe &gt; c:\test.txt, but still no joy.  So, aside from stating that the binary that I am trying to run is poorly written, is there anything I can do to remedy this? Keep in mind that I do get valid output when simply running the exe, it just won't print nicely to a file. Obviously the output is there, the question is if there is some way to catch it.