xcopy /d copy all files every time, even unchanged files - backup

i try this command line
xcopy e:\myfolder /EXCLUDE:excludeList.txt \\192.168.158.15\public\comp\myfolder /E/I/D/R/H/Y
the command copy all files every time even unchanged files
i use /d that suppose to copy just newer files.

a small test shows it does work. you must have other problem ...
edit
in netwoek enviroment - you should add /z

Related

How to launch a .bat file in VB without associating the file with the program that launched it?

Ok, the the question looks freakish, but this is sort of a continuation of the question I posted
here.
So, I create a .bat file in Visual Studio with certain lines and launch it, but it basically doesn't find the files it needs, but if I launch the .bat file it created manually, it works.
The problem, as far as I see it, is that the .bat file the program launches isn't the same as the one that is created in the folder?
The .bat files use the command line interface of Asesprite found here, e.g. :
#set ASEPRITE="C:\Program Files\Aseprite\aseprite.exe"
%ASEPRITE% --batch animation.ase --scale 2 --save-as animation-x2.gif
I'm not sure which part of the VB code I'd need to share, so ask if needed.
The error in .bat goes something like:
C:\Users\User\Desktop\aseConverter\aseConverter\bin\Debug>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif
File not found: "skeleton2_gib3.ase"
Error loading file "skeleton2_gib3.ase"
A document is needed before --save-as arguement
The first line should not be the Debug folder, but the location the .bat file was created in. I've no idea how to fix it.
It SHOULD be
C:\Users\User\Desktop\skeleton>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif
The problem here is that the batch file references files without path. Therefore the files must be in current working directory of the batch file.
But the batch file respectively command line interpreter cmd.exe is called by the VB.net without setting the working directory. Therefore the current working directory set by Windows for the batch file is the same as of the starting VB.net application.
But the starting application creates the batch file and the other files in a different directory, not in its own current working directory.
One solution is changing current working directory inside batch file to the directory the batch file is stored. This can be done by referencing argument 0 of the batch file which contains name of batch file with complete path.
What does %~dp0 mean, and how does it work? explains how to get drive and path of batch file.
Therefore one solution is to use a batch file like below:
#echo off
cd /D "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
See help output after executing cd /? in a command prompt window for meaning of parameter /D (change also drive if necessary).
An explanation for %~dp0 can be read on running call /? or for /? in a command prompt window.
Another possibility would be the usage of following batch code:
#echo off
pushd "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
popd
The difference to command cd is explained in help which is output in a command prompt window after executing pushd /?.
Best would be to create the batch file with all files referencing with complete path, name and file extension.

Move or Copy Files within subfolders to another folder

I've been searching around for quite some time but nothing I've found seems to work for me.
I would really like to move the files to another folder on the same drive if possible just in-case the drive happens to be low on space. but none of the move scripts i found seemed to work for me.
i've tried using move, move-items, copy, xcopy, and even robocopy.
robocopy is the only one to work for me so far even tho its creating a new file, it also creates a subfolder that the file is in. in the new location.
so this how my work looks so far
D:\DVDBD-Projects\Project1\
Movie1\
Movie2\
Movie3\
there is a .mkv file in each movie folder and I would like to move the .mkv in each folder under projects to a new location without creating the folder it was originally in.
So the .mkv files will be moved to D:\DVDBD-Projects\Complete without any folders just mkv files.
This is my code
robocopy "D:\DVDBD-Projects\Project1" "D:\DVDBD-Projects\Complete" *.mkv /s
this will copy the files to the new location but also create the movie1 folder and so on. if i dont use the /s switch it wont look inside the subfolders and copy the files.
So i was hoping you guys could help me out, is there a way that i can copy or move just the .mkv files to the complete folder.
i plan on adding this code to script that encodes the movies from my camera so it saves me alot of point and clicking and cutting and pasting.
*note - looks like i can use this code
pushd "D:\DVDBD-Projects\Project1"
for /r %%a in (*.mkv) do (
MOVE "%%a" "D:\DVDBD-Projects\Complete\%%~nxa"
)
popd
this will take all files from subfolders and move them to the destination folder
i could probably also install xxcopy which extends xcopy which would allow me to copy the files from sub directories without creating new folders in the destination
for /f "delims=|" %%s in ('dir /ad/b') do robocopy "\\source\%%s\" "destination\" *.mkv /s

xcopy "Access denied" with /y /o /s /c /h

I'm currently refining and updating my offline virus database updater for Malwarebytes. It's simply all the Malwarebytes data from C:\ProgramData\Malwarebytes (virus database, build number, etc) inside an SFX .exe archive set to run a batch file after successful extraction.
The Problem
My existing updater works by copying each file with individual xcopy commands, but this time I want it to simply copy the whole folder. But when trying to xcopy to C:\ProgramData, I get "Access denied" for everything.
This occurs even though I'm using the /y and /o switches and running the .exe as Administrator (from the context menu) to achieve elevated permissions. I know that I'm hitting the right directory and that the update does work with a manual copy and paste of the folder.
Is it just that it's not possible to command-copy a folder to ProgramData in Windows 7?
Extra Information
Inside the SFX .exe archive, I have a folder called "Malwarebytes" and a batch file. This is the only relevant segment of the batch file (I have independently confirmed that the rest of it works):
xcopy "Malwarebytes" "C:\ProgramData\Malwarebytes"\ /y /s /c /h /o
Odd.. It just started working.
The only idea I have for this is that when I was trying this, I was trying it with an activated version of Malwarebytes, which means that it was running a service in the background, whereas this time I was not using an activated Malwarebytes'.
This could have possibly been denying access to the files because they were in use.
I don't know. Thanks anyway, guys.
I have encountered this problem without pin pointing the problem However I used Robocopy instead. So simply replace xcopy with Robocopy with appropriate switches and it should work ...

Delete temporary files on startup

I have a program which when it runs it fills Temp folder with lots of .tmp files. This is causing C drive to fill up. I have been asked to investigate if it's possible to write a script in dos to delete temporary files on startup. I also wish to delay the program starting until all files are deleted. This would need to happen every time on start-up. It would be great if this could be installed via a flash drive.
I would be grateful on any pointers on how this could be done
The little batch I am using to delete my temporary files:
#echo off
rd %temp% /s /q
md %temp%
cls
echo Temporary Files have been deleted!
echo.
pause
%temp% is a path which always results in your current temporary folder. However note that there are more temporary file locations like C:\Windows\temp.
If you just want to delete TMP files, go with del C:\<MyPath>\*.tmp.
There are probably more sophisticated ways, but the good old fashioned del c:\Temp\*.* should be a good start.
There's a list of all the options, here: http://www.computerhope.com/delhlp.htm
You will probably want /F (delete read only), /S (sub-directories) and /Q (quiet)
I assume, the following row in c:\autoexec.bat file may help:
del c:\path\to\temp\files\*.tmp
Cheers for replies. This is what I'm using
c:
cd \
cd "c:\Documents and Settings\user\Local Settings\Temp\"
del *.tmp /f/s/q
echo All tmp files deleted.
pause
This seems to do what I want it to do. Now I need it to do this everytime PC starts up. Is there a way to install this via flash drive? ie write a batch file with all commands, put on flash drive. double click .bat file, now installed and will run on startup? (Have a number of PCs which need same thing)

script to move all files from one location to another location

can someone help me with a dos script to move all files from one location to another location
move <sourcepath>\*.* <destpath>
IE, if you wanted to move all files from c:\test\ to c:\test2
move c:\test\*.* c:\test2
if you want to suppress the prompt to overwrite files
move /Y c:\test\*.* c:\test2
If you want to move from the current directory, you can specify just the *.*. Also you can do relative paths. So if you want to move the current directory's files up one directory, you'd do
move *.* ..
.. being the shortcut for "up one directory"
If it's across the network, you can use a UNC path to authenticate as the user you're logged in as or map a drive (using the NET USE command) to specify a username/password on the remote computer, then copy using that drive letter. You can then delete the drive letter after you're done. UNC paths look like \\computer\share\folder\file.txt
I think this one
C:\> MOVE /Y *.* C:\Destination
should be corrected.
Use Robocopy. In Windows 7 and Windows Server 2008 R2 you can even run it multi-threaded using the /MT[:n] switch. From my daily "sync-before-shutdown" script:
Robocopy "d:\dev" "\\dolores\backups\carrie\dev" /e /MT /njh /njs /nc /np /nfl /ndl
(all the /n.. switches suppress console output which helps to speed up the copying process).
To move the files, use either /MOV or /MOVE (to move all subfolders) instead of /E.