Replace command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kizoku1988
Posts: 5
Joined: 07 Jun 2012 18:53

Replace command

#1 Post by kizoku1988 » 07 Jun 2012 19:12

====================================================================================
:: UPDATE.bat
:: Updates the Chosen Directory with the Latest Files
::
@ECHO OFF

REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\"*.* "C:\distributionpt" /A
REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\"*.* "C:\distributionpt" /U

:END
====================================================================================
Can anyone tell me if im doing something wrong cause the new files are not being copied or replaced by new ones..

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Replace command

#2 Post by abc0502 » 07 Jun 2012 20:03

look at the differance in red & green:
REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\"*.* "C:\distributionpt" /A
REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\"*.* "C:\distributionpt" /U

REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\*.*" "C:\distributionpt" /A
REPLACE "C:\Documents and Settings\NGWC\Desktop\distributionpt\*.*" "C:\distributionpt" /U

kizoku1988
Posts: 5
Joined: 07 Jun 2012 18:53

Re: Replace command

#3 Post by kizoku1988 » 07 Jun 2012 20:51

Its still not working... what im trying to do is to to keep a folder of Internet explorer favorites updated, so when someone updates/adds new favourites (most probably on a server ), it will be updated in the folder (on the running pc) too.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Replace command

#4 Post by abc0502 » 07 Jun 2012 21:44

I tried the code and it work with no errors at all,i tested with two folders 1 and 2 on the desktop and here is the code:"from cmd window and from a batch file"

Code: Select all

C:\Users\Admin\Desktop>replace "%cd%\1\*.*" "%cd%\2" /A

the result

Code: Select all

Adding C:\Users\Admin\Desktop\2\file_1.txt
Adding C:\Users\Admin\Desktop\2\file_2.txt

try using to avoid spaces in documents and settings
REPLACE "%userprofile%\Desktop\distributionpt\*.*" "C:\distributionpt" /A

and why using switch /U too use /A or /U and i suggest /A

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Replace command

#5 Post by abc0502 » 07 Jun 2012 22:01

Sorry,
u are right the files when i modify it it dosn't updated in the destination folder so use
/U /S switchs together it will update the new or modefied files only.and don't use the /A switch it should be like that:
REPLACE "%userprofile%\Desktop\distributionpt\*.*" "C:\distributionpt" /U /S

kizoku1988
Posts: 5
Joined: 07 Jun 2012 18:53

Re: Replace command

#6 Post by kizoku1988 » 07 Jun 2012 23:44

the /A switch will add files new files which are not in the destination folder.
the /U /S switch will update files which are already in the folder but updated...

the thing is, what if i have an whole subfolder in that folder itself? it never copied the folder over...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replace command

#7 Post by foxidrive » 07 Jun 2012 23:47

You might find that Robocopy is better to mirror a folder of shortcuts, if that is what you want to do. It will copy new ones and changed ones and delete ones that have been removed.

kizoku1988
Posts: 5
Joined: 07 Jun 2012 18:53

Re: Replace command

#8 Post by kizoku1988 » 08 Jun 2012 00:24

Im sort of backing up the files, not really just shortcuts. it can be documents etc.
robocopy command doesnt seem to be working on my cmd

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replace command

#9 Post by foxidrive » 08 Jun 2012 02:48

Robocopy is a good tool for that.

It's standard in Vista and Windows 7 and can be downloaded for XP from Microsoft.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Replace command

#10 Post by abc0502 » 08 Jun 2012 03:23

then u should use the copy command, it is a bookmarks so if new one exist it will be copied if old one will be re-copied and if one deleted the user should then choose by himself wether to remove the bookmark or not the main idea which u explained is giving every one all the bookmark if there is new

kizoku1988
Posts: 5
Joined: 07 Jun 2012 18:53

Re: Replace command

#11 Post by kizoku1988 » 08 Jun 2012 03:46

ok.. im using robocopy.. it does what i want.. but the problem now is.. can it run as a .bat file? cause when i paste in the code in cmd, it works, but when i use as .bat it doesnt...

=============

@echo off

robocopy "C:\Documents and Settings\NGWC\Desktop\RoboTest" "\\192.168.50.1\train-mode\RoboTest" /MIR /Z

=============

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replace command

#12 Post by foxidrive » 08 Jun 2012 05:55

Put this as the last line and see what error message is on the screen.

pause

Post Reply