How do I copy from numerous release directories to a single folder - deployment

Okay this is and isn't programming related I guess...
I've got a whole bunch of little useful console utilities scattered across a suite of projects that I wrote and I want to dump them all to a single directory to make using them simpler. The only issue is that I have them all compiled in both Debug and Release mode.
Given that I only want the release mode versions in my utilities directory, what switch would allow me to specify that I want all executables from my tree structure but only from within Release folders:
Example:
Projects\
Project1\
Bin\
Debug\
Project1.exe
Release\
Project1.exe
Project2\
etc etc...
To
Utilities\
Project1.exe
Project2.exe
Project3.exe
Project4.exe
...
etc etc...
I figured this would be a cinch with XCopy - but it doesn't seem to allow me to exclude the Debug directories - or rather - only include items in my Release directories.
Any ideas?

You can restrict it to only release executables with the following. However, I do not believe the other requirement of flattening is possible using xcopy alone. To do the restriction:
First create a file such as exclude.txt and put this inside:
\Debug\
Then use the following command:
xcopy /e /EXCLUDE:exclude.txt *.exe C:\target
You can, however, accomplish what you want using xxcopy (free for non-commercial use). Read technical bulletin #16 for an explanation of the flattening features.
If the claim in that technical bulletin is correct, then it confirms that flattening cannot be accomplished with xcopy alone.
The following command will do exactly what you want using xxcopy:
xxcopy /sgfo /X:*\Debug\* .\Projects\*.exe .\Utilities
I recommend reading the technical bulletin, however, as it gives more sophisticated options for the flattening. I chose one of the most basic above.

Sorry, I haven't tried it yet, but shouldn't you be using:
xcopy release*.exe d:\destination /s
I am currently on my Mac so, I cant really check to be for sure.

This might not help you with assembling them all in one place now, but going forward have you considered adding a post-build event to the projects in Visual Studio (I'm assuming you are using it based on the directory names)
xcopy /Y /I /E "$(TargetDir)\$(TargetFileName)" "c:\somedirectory\$(TargetFileName)"

Ok, this is probably not going to work for you since you seem to be on a windows machine.
Here goes anyway, for the logic.
# From the base directory
mkdir Utilities
find . -type f | grep -w Release > utils.txt
for f in $(<utils.txt); do cp $f Utilities/; done
You can combine the find and cp lines into one, I split them for readability.
To do this on a windows machine you'll need Cygwin or some such Unix Utilities handy.
Maybe there are tools in the Windows shell to do this...

This may help get you started:
C:\>for %i in (*) do dir "%~dpi\*.exe"
Used in the dir command as a modifier to i, ~dp uses the drive and path of everything found in (*). If I run the above in a folder that has several subfolders containing executables, I get a dir list of all of the executables in each folder.
You should be able to modify that to add '\bin\release\' following the ~dpi portion and change dir to xcopy. A little experimentation should make it pretty easy.
To use the for statement above in a batch file, change '%' to '%%' in both places.

Related

Comparing & Copying Newer Files

I have a series of E-mail templates stored on a DFS fileshare.
I would like to have a logon script so that when a user logs on, it will cycle through each template in \\LAN\Files\Office Templates\Outlook, compare the LastWriteTime and then copy across any of the newer files from the DFS share to the local folder %APPDATA%\Microsoft\Templates
Currently the folders look like this:
(I am aware at the minute they have the same date, but they won't in the future)
If anyone can help me with this then I would appreciate it very much.
Thanks in advance.
I'd use XCOPY, it's built into most versions of windows and is purpose designed for copy operations.
xcopy <Source> <Destination> <Parameters>
It's got many options, so worth reading the documentation link above.
Your copy is the most simple and needs no extra params. By default this will copy any files from Source that are newer, or do not exist, to Destination:
xcopy "\\LAN\Files\Office Templates\Outlook" "%APPDATA%\Microsoft\Templates"
Or the other option is to use Group Policy Preferences, but that's offtopic for here, more suited to ServerFault.

Zip files with encryption in a remote share, keeping orignal names and location

My team faces the need to encrypt all files in a repository with AES256. For this purpose, we decided we are going to zip all files with such encryption, using the same key for all of them.
The problem we have is that these files sit in a NAS, so from windows boxes they are accessible by \ to them.
The directory structure is something like this:
Original Structure:
Root
-1
|--folder1
|---file1.ext
|---file2.ext
|--folder2
|---filea.ext
|---fileb.ext
|--folder2.a
|---filec.ext
and so on...
Essentially, what we need is to have all the original files contained in a zip file, keeping their original names, which would be something like this:
Desired Outcome:
|-Root
|-1
|--folder1
|---file1.zip
|---file2.zip
|--folder2
|---filea.zip
|---fileb.zip
|--folder2a
|---filec.zip
and so on...
To accomplish this, we tried a batch script that calls 7zip, but it only works if it's run from the root directory, which is something we cannot use as the files are not in a server.
Here is the syntax of the batch script we came up with:
FOR /R %%i IN ("*.wmv") DO "C:\Program Files\7-Zip\7z.exe" a -mx0 -tzip -pPasswordHere "%%~dpni.zip" "%%i"
But, as wrote previously, it only works when run from the root folder, which is something we cannot do as files sit on a network location.
Mapping the drive or making a symbolic link to it doesn't do the trick either.
I've also checked on 7zip to do this, namely, making use of its "-r" operator, but I couldn't find a way to get the desired outcome (namely, recurse through all folders in the remote tree structure -there are a lot of them...- and keep the original file name).
I'm open to any suggestions as any kind of script, trick or guizmo that gets the job done will be more than welcome. =)
Thanks a million in advance!,
Sebas.
----SOLUTION----
I actually found a sollution here, mapping the drive in a different way (it's so simple it just made me feel stupid(er), but it's altogheter beautiful).
Using the batch script below, the remote share can be mapped like so:
You can map a drive using
net use X: \\server\directory
and then you can change to that directory using
pushd X:
(Post from which the answer was taken from: Batch File Iterating through files on a local network server)

MS-DOS commands doesn't work (COPY and ERASE)

I have done this .bat file to copy some maps and textures from my USB drive to the valve installation path, but it doesn't work, why?
#echo on
COPY \CS-Fix\Maps\*.* %PROGRAMFILES%\Valve\Half-Life\cstrike\maps
COPY \CS-Fix\Textures\*.* %PROGRAMFILES%\Valve\Half-Life\cstrike\
ERASE %PROGRAMFILES%\Valve\Half-Life\cstrike\maps\de_shipment.bsp
pause
What is wrong?
The %PROGRAMFILES% indicates that you're using Windows, not MS-DOS.
MS-DOS was Microsoft's variant of DOS, an operating system that preceded Windows.
Anyway, two main problems are apparent to my tired eyes:
Paths that possibly have spaces and are not quoted.
Probably no write access to the relevant folders.
To fix the first problem, quote paths.
The second problem is only a problem in Windows Vista and later.
You can probably fix that by running the batch file from an elevated command prompt.
I assume that the batch file is sitting on and being run from your thumb drive.
Do the paths need to be quoted?
#echo on
COPY "\CS-Fix\Maps\*.*" "%PROGRAMFILES%\Valve\Half-Life\cstrike\maps"
COPY "\CS-Fix\Textures\*.*" "%PROGRAMFILES%\Valve\Half-Life\cstrike\"
ERASE "%PROGRAMFILES%\Valve\Half-Life\cstrike\maps\de_shipment.bsp"
pause
You might need to quote things. %PROGRAMFILES% probably expands out to C:\Program Files. Try something like this:
#echo on
COPY "\CS-Fix\Maps\*.*" "%PROGRAMFILES%\Valve\Half-Life\cstrike\maps"
COPY "\CS-Fix\Textures\*.*" "%PROGRAMFILES%\Valve\Half-Life\cstrike\"
ERASE "%PROGRAMFILES%\Valve\Half-Life\cstrike\maps\de_shipment.bsp"
pause

How to delete files from a list?

I have a filesystem that uses a hash algorithm to organize files. I have used xcopy in the past to copy files to a different location by passing in a file that has a list of all the files and having it iterate through it. The script looks similar to the following:
for /f "delims=, tokens=1,2,3" %i in (D:\foo.csv)
do echo F | xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"
However, now I've run into a situation where in addition to copying the files that are provided in the foo.csv file, I want them to be deleted as well. I looked at the xcopy documentation and couldn't find anything. Is there someway I can accomplish this, even if I have to run another script to go through the same list of files and delete them after using xcopy?
Thanks!
You can use parenthesis to indicate multiple commands to be excecuted by the for operand:
for /f "delims=, tokens=1,2,3" %%i in (D:\foo.csv) do (
echo F | xcopy /i /d "Z:\%%i\%%j\%%k" "Y:\%%i\%%j\%%k" >> "D:\xcopy\Log.txt"
del /F "Z:\%%i\%%j\%%k"
)
I'm not familiar with Windows (I'm happily using Gnu/Linux since 1993), but perhaps you could add some command with variables like del %n somewhere (or replace xcopy with your own .bat file doing what you want)
From the look of it you can use move command instead of xcopy, since you're not using any extended features from xcopy. The '/d' is supposed to be used to only copy the files if they are newer, not sure how useful that is for your purpose since you want to delete them. Otherwise, move doesn't have many more options to speak of.
Another possible, and slightly more sophisticated, method is robocopy.
robocopy /MOVE /XO "Z:\%i\%j\%k" "Y:\%i\%j\%k"
The /MOVE would delete both folders and files after copying, and /XO flag excludes older files from being copied. robocopy is primarily available in newer operating systems (i.e. Not XP). You can check the above mentioned reference for more details.
Hope this helps. Although, just using del as previously mentioned should work fine also.

How can I remove a Windows directory without following junction points?

I have a Perl script that needs to delete a directory with all its contents.
Sometimes this directory contains a junction point into another directory. If I rmtree() naively, the rmtree() call will also delete all the files inside the target folder of the junction. I'm looking for a way to not do that, and instead just remove the junction.
Non Perl solutions would also be appreciated.
I just typed "junction point" into Google and found my way to
http://en.wikipedia.org/wiki/NTFS_junction_point
Command Prompt (cmd.exe)
The dir
command in Windows 2000 or later
recognizes junction points, displaying
instead of in
directory listings (use dir with the
/A or /AL command-line switch).
Any
commands that would normally affect
files inside a normal directory will
act the same here. Thus the command
del myjunction should not be used —
this will just delete all the files in
the targeted directory.
The commands
rmdir and move work fine with
junctions, with the caveat that move
won't let the junction move to another
volume (as opposed to Windows
Explorer, as mentioned above.)
The
rmdir command is safe in that it only
deletes the junction point, not the
targeted files. Whilst walking through
the directory with the command line
interface, files can be deleted, but
unlike explorer, directories can also
be deleted (using rmdir /s dirname for
example.)
Using the linkd command with
the /d switch is a safe way to delete
junction points.
From what I can see you can, for example, use dir and grep the output for <JUNCTION> or use the Windows rmdir. I think you can use either of these from Perl via system.
To find out where are the reparse points (or "junction points", if you will):
dir /a:l /b > myjunctions.txt
Will show all reparse points in the current directory. You can add /s, but beware that reparse points inside reparse points will be listed as well.
Suppose myjunctions.txt contains the line x:\subdir\foo. To remove it, you issue
fsutil reparsepoint "x:\subdir\foo"
And voilá! Your junction point is gone, and the original directory is untouched!
FastCopy utility does this: http://ipmsg.org/tools/fastcopy.html.en
I am using this program for copying or deleting folders that may contain junctions as subfolders so that the junction targets remain untouched. The junction points are properly copied while copying, even when the target drive is different.
Windows Explorer at least in Windows 7 Ultimate works also as wanted while deleting - junction targets remain intact.
But copying folders that contain junctions as subfolders in Explorer still does not work as intended - it actually does something that I cannot yet perhaps quite entirely describe: the junction folders seem to be copied as normal folders, but their content is empty.