seting up a template folder copy/ past system with batch - batch-file

I have a foldering system setup consisting of a “master folder” wich varys in name holds two sub folders, the sub folders though are always called CTB and DWG. I want the contents. of the DWG folder always to be coppied to the desktop and the contents of the CTB to always be coppied to C:\ICT\Autocad_2010\CTB. Remembering that the master folder varys in name pending on the project.
Is this possible with batch?
somthing like:
XCOPY %0\DWG\*.* c:\ICT\AutoCAD_2010\CTB
Nevermind i got it
XCOPY "%cd%\DWG\*.DWG" c:\
however how do i copy it to the desktop?

try this to copy to the current user desktop
xcopy "dwg\*.dwg" "%Homedrive%%Homepath%\desktop"
or this to copy to all users desktop
xcopy "dwg\*.dwg" "%allusersprofile%\desktop"

Related

Another RoboCopy File / Folder Migration Q

Hi Sorry to ask another question regarding robocopy but by its very nature it is quite diverse so I need to be clear on what I am trying to achieve.
Scenario.
Moving from a Nas to a windows file Share , Completely New ACL's will be created and inherited from the new share already setup . SO this is a straight file and folder copy with mirroring.
I decided to use powershell to run the command - it felt right at the time and achieved the desired result on a few shares .
I mapped the drive and ran the following .
robocopy z:\"Dept Folder 1"\ E:\Shares\deptdata\"New dept folder" /e /LOG+:file /v /TEE
robocopy z:\"Dept Folder 2"\ E:\Shares\deptdata\"New dept folder2" /e /LOG+:file /v /TEE
The files and folders copied as expected inheriting the new ACL's The first Job finished and then moved on to the second copy and again completed successfully.
What I would like to do now on some of the larger shares is incorporate the mir command as I need to keep a constant mirror on all folders until such time as I have tested the new ACL's and I have mapped the new drive via GPO.
My First Question knowing the behaviour when having batched commands is this .
When using the Mir command will the first command in the batch continue to mirror
the share and move onto the next Mirror command and so forth. or will it just sit their mirroring the first command and not move onto the second?
If it wont move on to the next command how do I achieve that is it possible? would i have to run multiple mirror commands at the same time and not batch them up in one?
When the Mir command is running if I add new files into the New destination will those files get deleted, or is it only mirroring the source and doesn't care about new files in the destination?
Where would I specify the MIR command?

Batch file to copy folder to multiple network destinations

I have been able to copy files from 1 location to another using the batch file.
However I need to copy the complete folder from one server to multiple servers.
Example;
Local machine name :
LOCAL
Destination machines :
Network1
Network2
folder that i need to copy
Local\d:\Hello
The whole folder hello and its contents to be copied
to
Network1\c
Network2\c
So the folders thats created should be like (with all the file within)
Network1\c:\Hello
Network2\c:\Hello
Looks like you might want to use xcopy. See below;
batch/bat to copy folder and content at once
You should end up with a script like this;
xcopy d:\Hello \\Network1\c$\ /E
xcopy d:\Hello \\Network2\c$\ /E

7zip adding 'DA' instead of 'D' attribute to directories

I'm trying to automate a task with a batch-script. Basically it should take a .html-File and a directory and zip them together.
7z a -r MyZIP.zip .\My-Folder
7z a MyZIP.zip .\MyFile.htm
It also "works". I can unzip it and I get everything back the way I put it in. Now I'm unzipping this on an iOS device and the folder suddenly is a 0 byte file without content.
I've compared the ZIP created by my script and the one I get when I do it by hand and it looks like the attributes on the folder are set differently.
When I do it by hand (then it works btw.) the folder has the attribute "D" and when my script does it it has the attribute "DA".
Does anyone have an idea why or how I could remove the "A"-attribute?
Any help would be appreciated.
Ok it turns out it wasn't 7zip that was creating the issue, but the xcopy command. When I copied by hand the directory had the correct 'D' attribute.
To make it work I switched from xcopy to copy

How to create Backup Batch file that copys only modified files & delete the dest files/folders that do not exist in the source?

I want to create a backup Batch file that meets these requirements:
Requirement:
1-Only copy the source files if the source file got modified.
2-If the destination contains the files/folders that do not exist in the source, then the destination files/folders will be deleted.
3-Copies all subdirectories, even if they are empty.
4-If something happened that make the coping process uncompleted (ie copied unsuccessfully), the program will revert & keep the old version of the destination folder.
5-The batch file should run at the time i turn off my PC or at 7pm Daily.
So, i tried this
xcopy C:\MyProject N:\backup\MyProject /V /Y /E /D
Note: /v=Verify, /y=No prompting /e=subdirs /d=Copy only changed
However, after running the batch, it did not delete the files/folders mentioned in requirement 2. Also, i don't know how to do the requirement 4 & 5.
I searched many questions but seem they didn't have the code to meet requirement 2 & 4 & 5.
I don't want to use backup tool in Win7 since it is very heavy & it requires a big backup disk space. I prefer something simple (why didn't Window make things simple?? ).
Backup is very important when u do the project, I hope my question will help a lot of other programmers.
Can anyone know a good solution for this?
If you want a mirror backup, which only copies new and changed files, removes files that no longer exist in the source - then Robocopy is built in and can do that. A batch file that is scheduled at 7pm daily will work.
Your requirement #4 is something that I haven't seen in any backup programs, including Robocopy.
I recently wrote a batch file like this for an old XP machine, since I didn't trust the format produced by NTbackup to be readable on future machines. E.g. Windows 7 and 8 require a download of some sort of converter: forget that. My batch file lives in the root C:\ directory, and I have a shortcut in my "tools" program list.
Write the file in Notepad, and save as e.g. c:\backup.bat. Run it from the "Run" command. The first time it runs, all the directories you specify will be copied exactly to your backup drive, including all subdirectories (I use a 4 Gbyte thumb drive: you may well need larger). The first time, my small 3 GB or so of stuff took about 4 minutes on an old XP machine.
Interestingly, the total uncompressed backup produced this way is no larger than the backup produced by NTbackup in Windows XP in that program's unreadable format.
Here's a batch file, with comments (REM)...
REM backup.bat
The xcopy line below is for stuff in directory c:\anydir and its subdirectories, being copied to a directory \anydir on an e: drive (e.g. USB drive).
REM The actual command:
xcopy c:\anydir e:\anydir /i /s /y /d
For other directories, just change the c:\directory and e:\directory names in the xcopy command. Watch out, however, for names like My Pictures, with a space: you must rename them (just delete the space), so that DOS recognizes them.
REM finish
exit
The /i means make any (sub)directories that don't exist on the backup drive. This therefore copies the whole branch from the c: directory where you start.
The /s copies source directories and subdirectories unless they are empty.
The /y says don't ask about over-writing existing files.
The /d says only copy files of a later date: perfect for backup, and very fast.
The files are exactly as original: no weird backup format.
With regard to the questioner's question #4, I think just running the backup again would overwrite any failure. But if that fails, wipe your backup drive and start over. And question #5...XP (and I think 7) allow scheduled tasks from the Startup menu: just insert c:\backup.bat in the list. But I haven't tried that.

Create a batch file to create multiple folders within many folders

I am trying to create a batch file which will create folders within all sub-folders of a given folder. So for example if it ran in the directory C:\Example, it would create a folder a, b, and c under each of the 20 folders regardless of their name.
It would be much easier to do this automatically rather than copy the .bat file to every individual folder to create the 5 same folders every time with just md.
So far everything I have created has been a disaster, so I'm hoping someone can help me out with this.
for /d %%x in (*) do mkdir "%%x\a" "%%x\b" "%%x\c"

Resources