Recursively copy files that match a wildcard combination but not create the directory tree in DOS - recursion

I found that I can use xcopy /s to copy all files that match a wildcard combination in a folder to another location. But this command re-creates the folder structure. I do not want the tree. I need just the files dumped into the destination folder. There are no duplicate files in the source folder.

You can use for command:
for /R %%x in (*.cpp) do copy "%%x" "c:\dest\"
If you want to run it directly from command prompt (not from a batch file) use %x instead of %%x.

For your purpose, instead of using xcopy you should use robocopy:
http://en.wikipedia.org/wiki/Robocopy
http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

Related

Recursively copy the *contents* of a directory

Using any of the standard Robot libraries, is it possible to recursively copy the contents of a directory to an existing destination directory?
Basically, I'm looking for the equivalent of the following shell command: cp -r foo/. bar (note the trailing dot)
I tried Copy Directory but this creates a directory foo inside bar (as documented) and it doesn't stop doing that even when supplying the trailing dot. Copy Files chokes when it encounters a directory.
Is there anything I overlooked? Or do I need to just call cp -r myself?
As I only need this to work on Linux, I ended up implementing a custom keyword calling cp -r. If this is ever needed cross-platform, then I'll follow the suggestions to directly implement it in Python.
Copy Directory Contents
[Documentation] Recursively copies the contents of the source directory into the destination.
[Arguments] ${source} ${destination}
Directory Should Exist ${source}
Directory Should Exist ${destination}
${result} = Run Process cp -r ${source}/. ${destination}/
Should Be Equal As Integers ${result.rc} 0

sftp uploading to non-existing directory

Say I have to upload file dir-a/dir-b/dir-c/xxx.txt using sftp
Should I create the target directory first?
Should I open target directory before copying the file?
If have to create this path dir-a/dir-b/dir-c - is it one command or three?
Should I create the target directory first?
Usually yes. SFTP servers usually do not create parent directory. But how hard is it to try first?
Should I open target directory before copying the file?
You do not have to. put command does accept a remote-path, which can be either absolute or relative to remote working directory.
If have to create this path dir-a/dir-b/dir-c - is it one command or three?
These are three commands:
mkdir dir-a/
mkdir dir-a/dir-b/
mkdir dir-a/dir-b/dir-c

nsis adds empty folders to the installer

The File below:
; Install common files
SetOutPath "${GameDir}\Mopy"
File /r /x "*.bat" /x "*.py*" /x "w9xpopen.exe" /x "Wrye Bash.exe" "Mopy\*.*"
filters out some directories that contain python files but still those directories are created (although empty, or containing empty subdirectories) when I run the installer. Those folders need to be included to the installer (if I get the terminology correct at "compile time") cause the installer has an option to install the python version of the program. I can't come up with a way to not add these empty folders. Is there some wildcard I could use to that purpose or should I go and remove the files on installation (using RMDir ?) ?
I'd say you have two options and one is indeed RMDir if you are OK with it possibly removing empty folders that the user created.
The other option is to not use File /r ... and instead use !system to execute something like a batch file that generates a text file with individual File instructions that you can !include. It would look something like this:
!tempfile files
!system '"mygeneratefilelist.bat" "${files}"'
!include "${files}"
!delfile "${files}"
and the batch file would use FOR and/or DIR to list and ECHO the File commands to %1...

Creating a terminal command in Minix

I want to create a command that runs an executable created by compiling a c program. I couldn't find a proper solution. Let's say I have a file named myprogram.c and compile it and have myprogram as . I want to type myprogram in any folder in my system and run it. How can I achieve this?
First find out what your PATH is
echo $PATH
For you this outputs
/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin
Then assuming your program is in the /usr/myprog directory, append /usr/myprog to your PATH (don't forget to separate directories with a colon :)
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin:/usr/myprog
Doing this tells the system when you don't specify an absolute path (like ./myprogram) to look in all the directories in PATH. It is good to add the absolute path of your executable to PATH because adding . to your PATH is frowned upon by some (see this question).
You have to add it in your PATH from your shell rc file
You place the executable into a directory that your shell already searches for programs, or you add your program's location to that list.
the $PATH environment variable contains this information. You can add myProgram's location to it, i.e. export PATH=$PATH:/new/dir, or just print out $PATH and copy myProgram into one of the paths listed there already.

How to copy selective folders into a different directory

folderA contains [dirA, dirB, dirC, fileA, fileB]
I want to copy folderA to folderA-copy without dirB and dirC how should I do that?
Use rsync command exclude option which provides you with option to enter regex for folder/files or specify a file containing all the directories you want to ignore or specify particular directory or file.

Resources