robocopy - search and copy to single folder

I've been putting off moving to Robocopy for some time now. I would like to have the copy progress display option (which xcopy lacks) so that i can see if large files are still being transferred. XCOPY does almost everything that I currently require... with one exception. I cannot find any way to have robocopy perform the following action in full:

1.) search the entire hard drive, beginning at the root of C:\
2.) locate all files of a specific extension (could be 1 file, could be 500 files) all in various subfolders.
3.) copy the files found to another drive and folder, say a network drive such as z:\data, WITHOUT keeping any folder structure. (aka "concatenate"  the structure).

example (old location):
c:\ralph.txt
c:\users\ken\my stuff.txt
c:\program files\notepad99\settings.txt

(new location - how it SHOULD look)
z:\data\ralph.txt
z:\data\my stuff.txt
z:\data\settings.txt

I'm currently using XXCOPY to handle this now however it's not free to use in a corporate environment. We are covered according to our M$ TAM, to use ROBOCOPY.

My OS is XP & SVR 2003 right now. I've also tried robocopy in Win 7 with the same results as above.

SIDE NOTE:   Any suggestions to use something like RICHCOPY should include how to get filters to work properly because as of today, richcopy copies EVERYTHING in EVERY FOLDER even though i specify exactly what extensions i want it to copy. I use the GUI, switch to advanced, make my settings, and then use the code generated on the "other" window, then paste it into an elevated command prompt with no luck. Others have posted with this same issue as well on the MS forums with no answers from the developer. I'm using the latest version from their site however my version number shows the word "static" instead of a number.

Can this be done?
teotwawkiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

t0t0Commented:
Surely, XCOPY's 'F' and 'Q' command line options control whether or not progress is displayed.... Or is this no help to you?
 
0
SuperdaveCommented:
I'd do this:

\cygwin\bin\find /cygdrive/c -name *.txt -exec cp {} . ;

It's free, it'll work, it's versatile (you can enhance the command to look at timestamps or whatever), and having cygwin installed might just come in handy in other ways.  No
harm with having it installed even if you don't use it for much.
0
SuperdaveCommented:
I think this should do it too, if you like Windows commands.

FOR /R %I IN (C:\) DO XCOPY %I

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Dustin_LoftisCommented:
Well, Robocopy does not appear to have a function that will rename the files on the fly when they have matching names, so it doesn't look like that would work.

If you wanted to do it manually, you could always run a Windows search for *.txt and mass-copy those files to a folder.  You'd have the file name problem there, too.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
t0t0Commented:
You need something like this:



@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('dir /a-d /b /s c:\*.txt') do (
   set folder=%%~dpa
   for %%b in ("!folder:~0,-1!") do (
      echo Copying %%a to z:\data\%%~nxb
      mkdir "z:\data\%%~nxb\" 2>nul
      copy /y "%%a" "z:\data\%%~nxb\%%~nxa" >nul
   )
)

exit /b
0
t0t0Commented:
Oops! Just noticed you want ALL the files copied to the SAME folder!!!

What if there are files with the same name but in different locations? - Should they be over-written, ignored or what?

The best approach would be to use my code above however, if you really want to copy global files to the SAME folder then this should do it.



@echo off
for /f "tokens=*" %%a in ('dir /a-d /b /s c:\*.txt') do copy "%%~nxa" z:\data\

0
teotwawkiAuthor Commented:
Wow. Just got back to my desk and had several great responses. I'll clarify a couple items from my original post.

1.) XCopy does what i need except for a couple items:
a.) couldn't get it to concatenate/consolidate files to a NEW single folder
b.) show a file copy progress meter (similar to robocopy's percentage and eta options) so i could easily see if the system was still copying, locked up, lost connectivity, etc. ******* This is not a 100% requirement for me but if it could do both, i was up for switching to it.

2.) I wanted to just go to Robocopy since I figured it could do the same things as XCopy + give me status + concatenate files into a NEW single folder (but it appears that it cannot do the last one???)

I do use XXCopy (from pixelab) which can do the same as XCopy + Robocopy's status/progress meter BUT it's not free for corporate use. We are not sure if we want to shell out a ton of $$$ to use XXCopy company wide. VBscripts don't easily show status either, right?

t0t0 - you've helped me before and i can quickly test the consolidation aspect of it. To answer your last question, I DO need it to take in account the same file names being copied to the new destination folder.
           a.) The first suggestion from t0t0 copies the file but dupes get overwritten.
            b.)  The last option from t0t0 using the tokens parameter did not copy all of the files. I purposely created 3 files on the system with .PS9 extensions, changed the script to search for that extension, and then executed it. It appears to have actually only copied the last file it found even though the output says:
The system cannot find the file specified.
        1 file(s) copied.
        1 file(s) copied.

 Right now, when "XXCopy" from Pixelab encounters an existing filename in the destination folder (say myfile.txt), it simply makes the second file = myfile00001.txt, the third file= myfile00002.txt, and so on.

All others who responded - thanks again! I will definitely look into those options tomorrow as well.

Finally, is there any way to get Robocopy to do this (some undocumented or unknown-by-me switch)?

0
t0t0Commented:
To be on the safe side, you should use this batch file.

Any errors (where files are not copied to z:\data) are written to a log file

Also, any duplicate named files which are not copied are also written to the log file.



@echo off
setlocal enabledelayedexpansion

echo Duplicate filenames that could not be copied to z:\data >"%~n0.log"

set files=0
set errors=0

set /p .=.<nul
for /f "tokens=*" %%a in ('dir /a-d /b /s c:\*.txt') do (
   set /p .=.<nul
   if not exist "z:\data\%%~nxa" (
      set /a files+=1
      copy "%%a" "z:\data\" >nul 2>&1
      if not !errorlevel! equ 0 (
         set /a errors+=1
         echo %%a >>"%~n0.log"
      )
   ) else (
      set /a errors+=1
      echo %%a >>"%~n0.log"
   )
)

echo.
echo %files% files were copied to z:\data
echo.
echo %errors% entries were written to the error log file: %~n0.log
echo.
exit /b
0
t0t0Commented:
Sorry, I did not see your latest comment before posting my code immediately above.

I will read your comment and respond accordingly.

In the meantime, there have =been some good suggestions from others. Please feel free to explore these too.
0
teotwawkiAuthor Commented:
Still no luck with Robocopy but the following code does appear to do what i need ...



@echo on
cls

setLocal EnableDelayedExpansion
set source=c:\*.PSX
set target="z:\test"
set /a cnt=500
set /a cnt2=0
set p-copy=no
for /f "tokens=*" %%a in ('dir %source% /b /s') do (
set B=%%a
:loop (
set /a cnt=%cnt%-1
set char=!B:~%cnt%,1!
if %char%-==.- set p-copy=yes
if %char%-==\- set /a cnt2=%cnt2%+1
if %cnt2% lss 2 call :loop

set /a cnt=%cnt%+1
set W=!B:~%cnt%,499!
set C=!W:\=_!
if exist "%target%\!C!" set p-copy=no
if %p-copy%==yes copy "!B!" "%target%"\"!C!"
set /a cnt=89
set /a cnt2=0
set p-copy=no
)
)

Open in new window

0
t0t0Commented:
Apologies for coming back to this one late.  I still have not had an opportunity to read your previous comment.

I'm going to be blunt here.

The code you submitted above is utter rubbish. I am offended that you should post that rubbish considering the code I posted myself.

You say the code appears to do what you want - nonsense! Just looking at the code I could tell it would not work. As it so happens, I did run the code and it crashed back out DOS with an error messege - as expected!

Please be warned, if you are not going to take our help seriously then I will not participate further.
0
t0t0Commented:
Right! I have read your earlier comment.

Firstly, I have an observation and that is, I really do hope you are NOT in charge of your comapny's IT department. I personally have little faith in your competence!

Right! Moving on...

My advice to you is: forget about Robocopy, Xxcopy and the likes. MS DOS provides ALL the tools necessary to do what you ask - even though what you're asking is unorthodoxed and bad practice.

Going on my previous observation (and as far as the points are concerned I'm kissing them goodbye here) you don't appear to have any basic understanding nor appreciation of the need for a hierarchical filesystem. To suggest copying global files to a single folder without considering the possible consequences makes me wonder what the hell your company is thinking of allowing you to tinker with their computer systems.

My criticisms aren't intended to insult you nor intentionally offend you.

If there is a problem with my code then please state why it does not meet your needs and how it can be adapted to do whatever it is you want to do.
0
t0t0Commented:
COMMENTS:

1) There is no indentation of code. This makes it difficult to visually group blocks of code.

2) Your variable names, B, W and C, are meaningless and give no clues as to what purpose they serve.

3) cnt, cnt2 and p-copy are almost as meaningless as B, W and C.

If you were to return to your code in 6 months time to modify it you would have trouble understainding your own code as would any other person.

4) The use of CALL is totally inappropriate and syntactically wrong.

5) You are not consistent with the use of doubl-quotes around filenames

6) What the hell is this: "%target%"\"!C!"? Are you sure you actually tested your code?

7) Your IF statements must be in the following format (or similar): IF "a"=="b"... (using double-quotes)


@echo on
cls
 
setLocal EnableDelayedExpansion
set source=c:\*.PSX                                                  Why is this NOT in double-quotes but...
set target="z:\test"                                                      this is? This should not be in quotes either.

set /a cnt=500                                                           )
set /a cnt2=0                                                             ) I'd have to study the code real hard to figure...
set p-copy=no                                                           ) out what these do.

for /f "tokens=*" %%a in ('dir %source% /b /s') do (
set B=%%a
:loop (
set /a cnt=%cnt%-1                                                   %cnt%-1 will NOT work! It should be: !cnt!-1...
set char=!B:~%cnt%,1!                                              nor will it work here.
if %char%-==.- set p-copy=yes                                  This is crap and...
if %char%-==\- set /a cnt2=%cnt2%+1                       so is this and...
if %cnt2% lss 2 call :loop                                           so is this. You can't use CALL on :loop.
 
set /a cnt=%cnt%+1                                                  This won't work and...
set W=!B:~%cnt%,499!                                             nor wil this.
set C=!W:\=_!

if exist "%target%\!C!" set p-copy=no                          This is absolute and utter rubbish and...
if %p-copy%==yes copy "!B!" "%target%"\"!C!"           so is this!

set /a cnt=89                                                             )
set /a cnt2=0                                                             ) And whatever function these are is anyone's guess!
set p-copy=no                                                           )

)                                                                              Code should have been indented...
)


So, all I know at this stage is that this code DOES NOT work. I haven't actually studied it to see what it's meant to do.
0
t0t0Commented:
So, going back to this code, why won't it do?



@echo off
setlocal enabledelayedexpansion

echo Duplicate filenames that could not be copied to z:\data >"%~n0.log"

set files=0
set errors=0

set /p .=.<nul
for /f "tokens=*" %%a in ('dir /a-d /b /s c:\*.txt') do (
   set /p .=.<nul
   if not exist "z:\data\%%~nxa" (
      set /a files+=1
      copy "%%a" "z:\data\" >nul 2>&1
      if not !errorlevel! equ 0 (
         set /a errors+=1
         echo %%a >>"%~n0.log"
      )
   ) else (
      set /a errors+=1
      echo %%a >>"%~n0.log"
   )
)

echo.
echo %files% files were copied to z:\data
echo.
echo %errors% entries were written to the error log file: %~n0.log
echo.
exit /b
0
teotwawkiAuthor Commented:
Again, thanks for the responses there t0t0... up until your last several. My response with the code above was not to offend you in any means. REWIND: please do not take my comments offensively because i'm not supposed to take yours in that manner.  Last time i checked, EE prefers their users to be civil and your responses are far from that. I am obviously not a programmer and do not live in my parents basement eating pop tarts and hot pockets all day long. So YES, I do have to spend some time searching for what I am looking for, whether it be on this site or elsewhere.  The last time i checked, that is the purpose of EE...right? To get answers... not attitude?
Now ... right back at you. I'm going to start by saying that you must be a talker... because your listening skills (translated here to be READING) must not be up to par. You clearly did not read the objective THUS wasted an inordinate amount of time for yourself and me. Then again, you probably will not read this post, either in part or in full. Hopefully you actually follow up with your customers (assuming that you do still have customers at whatever you call a job) as promised because you would be at the unemployment line if you did not. I did wait until the end of the day to actually look elsewhere to find something that actually copies the files, even though my question is not to find an alternative and you apparently cannot understand my objective in plain english.
Herein lies one of the problems: (t0t0) Apologies for coming back to this one late.  I still have not had an opportunity to read your previous comment.
Since you have not had time to read the post - let me sum it up. It does not do what i want. If i wanted to just log the files that didn't copy, I can do that myself without any help. Hell, I could email the results to myself with a single line of code too but that is NOT what I was looking for in the OBJECTIVE.
Now that we know WHY I POSTED ABSOLUTE "RUBBISH" as an ALTERNATIVE solution is that IT WORKS.
It was simply to say that this solution DOES search for and copy ALL of the specific files that i ask it to copy... including duplicate names! This "rubbush" will be used one time on a system prior to moving the remaining KNOWN data storage points (favorites, mydocs, etc).
DO NOT BOTHER TO REPLY UNTIL YOU ACTUALLY  TEST MY RUBBISH, WHICH IS ACTUALLY SOME ELSES RUBBISH THAT TOOK ME LESS THAN 1 MINUTE TO FIND VIA THE BIG "G".
(t0t0) My advice to you is: forget about Robocopy, Xxcopy and the likes. MS DOS provides ALL the tools necessary to do what you ask - even though what you're asking is unorthodoxed and bad practice.

Going on my previous observation (and as far as the points are concerned I'm kissing them goodbye here) you don't appear to have any basic understanding nor appreciation of the need for a hierarchical filesystem. To suggest copying global files to a single folder without considering the possible consequences makes me wonder what the hell your company is thinking of allowing you to tinker with their computer systems.

So what you are saying in your rants above is that no matter what the circumstances, end users will never store data, whether accidentally or on purpose, in folders where they could be missed during their own OR an IT new system deployment? If both of your customers (assuming you only have 2 customers instead of close to 40,000 like me) keep their data neatly organized within their t0t0 folders (also assuming that you hold their hands during every file and folder creation).  WTF AM I THINKING! As we buy NEW companies with WHO KNOWS WHAT ON THEIR SYSTEMS, WHO KNOWS HOW OLD, HOW MANY USERS HAVE USED THIS PC WITHOUT BEING REIMAGED, AND WITH DATA ALL OVER THE ##$@# PLACE, WE WOULD NEVER, EVER, NEED TO QUICKLY GO IN AND SEARCH FOR ONE OR MORE IMPORTANT .PST or .DOC FILES, MOVE THEM TO A SERVER, AND DEPLOY A NEW SYSTEM.....RIGHT?
Why would I ever want to perform such a ridiculous task as copying files to a single folder? See below...
I clearly understand the need for structure WHICH IS WHY I AM TRYING TO PULL A SPECIFIC EXTENSION INTO ONE LOCATION. Do you want to manaully locate 200+ email archives, save them to a share, reload the system, throw them back where they were before? I sure as %#@ don't want to do that. I want to collect them from wherever they are and place them into a single location. Now I can force a new GPO for allowing this NEW person at this NEW company that we JUST acquired and JUST reimaged to store ALL of their archives in ONE location. Easier for US to manage from that point on. Would I have 200+ archives. Not in my current position. However I can tell you that people in the legal system DO have that many because they require working with multiple clients at once, several of which are asked to provide emails as evidence in a case. Sure, everyone has external hard drives and cd/dvd burners to backup this stuff, but realistically, backups are only of any importantance to a user when the original data is gone. They seldom check the backups for verification that it actually worked. "well, i see my folder on the backup drive and it has my stuff in it." That happens SOOO often. Had they taken 15 minutes to open a few files from each folder to verify each bit had copied successfully, they would have known the backup did not truely work.
How about if that hard drive starts to fail in their system? I cannot sit there and try to remember file locations for 40,000 different clients... or can I? If we've never seen this system before, probably not (meaning it's not been on our domain, not receiving our group policy objects, and is not running a standardized company image). If they are an existing client that has been configured to our standards, then the answer is YES... i will know where 99% of their data is located.  I am going for whatever the user says that they CANNOT LIVE WITHOUT. Most of the time, it's the "My Documents" folders and email archives. If I've done my job of helping this user to orgainze his/her data, I know EXACTLY where that folder is located and that it also WILL contain the PST files that they absolutely must keep.
In the real world, users store data wherever they want. Even if you have your pretty little GPO, local system policies, forcing absolute paths via the registry, and so on in place, in the eyes of the user it's still the TECHNICIANS fault if data is missing. You can suggest backups to external storage devices, complete system image backups, and so on. Whether you're helping out a friend, work in a computer repair shop, or a HUGE corporation, you should still try to be respectful and try to educate the customer on "best practices".
I simply started this thread asking if ROBOCOPY could do this and I get some good alternatives from you and others but never an exact answer.. just insults from you... for me coming up with a some code that does actually work.
 In closing, i feel sorry that you need to belittle others in order to make yourself look superior and god-like. i really hope that you are acting in this manner because you had a bad day yesterday or that you were feeling pressure from your superiors to complete an urgent task. I pray that you are not treating any employee that you happen to manage in this manner. My advice to you t0t0, as you so wonderfully gave me your thoughts, is to RTFO (last letter stands for OBJECTIVES).
0
t0t0Commented:
Dear teotwawki

Than you for your very detailed reply (which I am yet to finish reading) however, I could not resist replying immediately to the part where you insist the code you posted above works and does what you want it to do.

Unfortunately (for both of us) I don't think you would understand a technical explanation as to why I blew a fuse when reading through your code. However, please allow me to point out just one aspect of your code which is 100% incorrect and would NOT work under ANY CIRCUMSTANCES. Then I will allow you to be the judge by asking you to confirm it yourself.

RUN 1
I created a SUBST'd drive Z: containing a folder Z:\Test\
I create a source folder off C:\ named C:\Source containing a single folder named C:\Source\Temp
I created the following files in C:\Source\

    file1.ps9
    file 2.ps9
    file.three.ps9
    file4.tmp

and the following files in C:\Source\Temp\

    file5.ps9
    file 6.ps9
    file.seven.ps9
    file8.tmp

I then set source to:

    set Source=C:\Source\*.ps9

RUN 1
This failed immediately. See Pic1.

I recognised the problem immediately. I had to edit the line:

    if %char%-==.- set p-copy=yes

to:

    if "%char%"=="." set p-copy=yes

And I did the same for:

    if %char%-==\- set /a cnt2=%cnt2%+1

to:

    if "%char%"=="\" set /a cnt2=%cnt2%+1

(I'm ignoring other errors on these lines of code for the moment)

I then re-ran the code and this time I received a far more serious error. See pic2.


   




Firstly, running the code gave me this error:

 

pic1.JPG
0
t0t0Commented:
Oops!... pressed ENTER by mistake!

Here is Pic2....
pic2.JPG
0
t0t0Commented:
I then changed the CALL :Loop to GOTO :Loop. The program just locked itself in and endless loop. I had to CTRL-C it to regain control of DOS.

No files were copied in all three attempted runs - OBVIOUSLY!

See pic3...




pic3.JPG
0
t0t0Commented:
So, do you still say your code works perfectly?

0
teotwawkiAuthor Commented:
You should have a motto "shoot first - then read the question later!" At least i'm in a better mood this afternoon.
well my best friend has a medical condition called ADD. He can't get through a paragraph so i guess i understand.

I simply did the following again JUST NOW on a brand new PC:
1.) made 3 fake files called "desktop.ps9" (after consulting Microsoft to see how to make a file of course because i am too stupid to do so...
2.) placed 1 in the root of C:, one in c:\temp, and one on my Windows desktop.
3.) Next copied MY code from above, pasted it into a new file called "test.bat" that resides on my desktop, removed the EXTRA SPACES AT THE END OF EACH LINE THAT EE AUTOMATICALLY ADDS when pasting code into their PROPER CODE field.
4.) i made another call to Microsoft to ask them how to launch my newly created batch file. WOW! They said i could just do this thingy with my mouse called a "DOUBLE CLICK"
5.) I did this "double click" thingy and VIOLA (WALLA for those that cannot spell)... My fake PS9 files exist in the destination directory!
So i guess i do insist that my code works... Shall we have a peeing contest next?

As Ochocinco says, "CHILD PLEASE!"

omg...it-works.jpg
0
teotwawkiAuthor Commented:
Taken from your rant again above but underlined where I modified it to bounce it back to you.
Unfortunately (for both of us) I don't think you would understand a technical explanation as to why I am correct and you are not when reading through your code. However, please allow me to point out that several of your "shoot-off-the-hip-without-fully-comprehending-the-scope-of-the-project-or-even-testing-out-your-own-code-and-being-shown-up-by-someone-who-admits-they-suck-at-coding" which include your code which is 100% incorrect and would NOT work under ANY CIRCUMSTANCES. Then I will allow you to be the judge by asking you to confirm it yourself.
Again, a wise man once said "you can put lipstick on a pig, but it's still a pig". Underneath all of that lipstick is still a pig. Some are pretty (like Miss Piggy) while others are not (homer's spider pig). Plus, Miss Piggy tells me she can't do it all.
Mine (aka the one I found in 1 minute) may not be Miss Piggy but in the end, Spider Pig wins the race.
SPIDER PIG

SPIDER PIG

Does whatever a SPIDER PIG does

Can he swing

From a web

No he cant

He's a pig

LOOK OOOUUUTTT!!!!

He is a SPIDER PIG!!
 
0
t0t0Commented:
teotwawki

I don't want to get into a slanging match nor lose sight of respect. If a painting is shit, I'll say it's shit. That's just my opinion. If I say a piece of code does NOT work, then I say so based on my knowledge of programming - not opinion.

I am trying to establish why you say your code works when quite evidently, it does not. Let me confirm I am running the code on a 32-bit XP SP3 box - not a mac or a linux box nor indeed Commodore 64 or ZX Spectrum.

Can we al teast agree you are running your code on an 32-bit XP box possibly upto SP3 with NTFS?

Can we also agree you are running the EXACT code as it appears below ?


    @echo on
    cls
 
    setLocal EnableDelayedExpansion
    set source=c:\*.PSX
    set target="z:\test"
    set /a cnt=500
    set /a cnt2=0
    set p-copy=no
    for /f "tokens=*" %%a in ('dir %source% /b /s') do (
    set B=%%a
    :loop (
    set /a cnt=%cnt%-1
    set char=!B:~%cnt%,1!
    if %char%-==.- set p-copy=yes
    if %char%-==\- set /a cnt2=%cnt2%+1
    if %cnt2% lss 2 call :loop
 
    set /a cnt=%cnt%+1
    set W=!B:~%cnt%,499!
    set C=!W:\=_!
    if exist "%target%\!C!" set p-copy=no
    if %p-copy%==yes copy "!B!" "%target%"\"!C!"
    set /a cnt=89
    set /a cnt2=0
    set p-copy=no
    )
    )


If that's the case then I need to establish how it is possible for the above code to work for you (I know why it doesn't work for me - that's not at issue here!).
0
t0t0Commented:
After you have responded to my previous comment perhaps you'd be good enough to explain why you are managing to run your code with success (which I only have your word for btw) and why it doesn't run on my system - I have provided hard evidence (screen shots) of your code clearly not working. Do you dispute this evidence?
0
teotwawkiAuthor Commented:
LOL. I actually like you and do respect you for your knowledge.

My systems that I was using last night:
1.) XP SP3 x86 VM running on Sun Virtualbox - all updates that were published to Microsoft Updates through Monday
2.) XP SP3 x86 VM running on a clustered vmware esx environment - all updates that were published to Microsoft Updates through Feb18th
3.) windows 7 x86 desktop - all updates that were published to Microsoft Updates through Monday

My systems today:
1.) windows 7 x86 desktop - all updates that were published to Microsoft Updates through Monday
2.) XP SP3 x86 VM running on Sun Virtualbox - all updates that were published to Microsoft Updates through today
These are 5 different systems for all intents and purposes. I will be offline for a while so i'll check back in later.
0
teotwawkiAuthor Commented:
Do you have a large amount of files on your system?

I turned echo ON originally to see what it is doing and it does loop for 30-60 seconds, depending on the system i am using. I just did this again on another system and it works. i will do screenshots tomorrow.
0
teotwawkiAuthor Commented:
See screenshot (7 total).
 

Snap1.jpg
0
teotwawkiAuthor Commented:
instead of doing 7 individual uploads, i've attached a zip file which includes the screenshots. obviously no logging in this to show failed or success.
snaps-of-file-copy.zip
0
t0t0Commented:
That's easy to do.... All you really need is the following code (and this is PROPER programming mind):


@echo off
setlocal enabledelayedexpansion

set source=c:\
set filetype=*.ps9
set destination=z:\test

for /r "%source%" %%a in ("%filetype%") do (
   set folder=%%~pda
   set folder=!folder:~0,-1!
   for /d %%b in ("!folder!") do (
      copy /y "%%~dpnxa" "%destination%\%%~nxb_%%~nxa"
   )
)
exit /b


NOTE: This is the building blocks of your requirements... If you want any bells and whistles (such as a progress indicator or listing to the screen) then these can easily be incorporated.


NOTE: What about duplicate files (again)?

Suppose someone has the following files:

c:\folder\file1.ps9
              file2.ps9

c:\backup\folder\file1.ps9


As you can see, in both cases their home directory is names "folder" so this is what happens:

   c:\folder\file1.ps9 gets copied as z:\test\folder_file1.ps9

   c:\folder\file2.ps9 gets copied as z:\test\folder_file2.ps9

however, when attempting to copy the file from c:\backup\folder\ this happens:

   c:\backup\folder\file1.ps9 cannot copy to z:\test\ because z:\test\folder_file1.ps9 already exist


Does that make any sense to you?

If so, is this something that needs to be addressed in your requirements?
0
t0t0Commented:
Do me a favour, please run the code i gave in my comment above and time it against your current code and report back any time differences. Thank you.
0
teotwawkiAuthor Commented:
thanks t0t0 for supplying some additional code. Yes, your code is about 3x faster that the one that i mentioned earlier.

what do you suggest as far as progress viewing?
0
t0t0Commented:
A true progress indicator would rely on an initial pre-scan of the entire drive taking note of the number of files that need to be copied. Better indicators rely on file sizes too.

A simple indication might just display the names of each file as they're being copied such as in the following code:


@echo off
setlocal enabledelayedexpansion

set source=c:\
set filetype=*.ps9
set destination=z:\test

for /r "%source%" %%a in ("%filetype%") do (
   set folder=%%~pda
   set folder=!folder:~0,-1!
   for /d %%b in ("!folder!") do (
      echo Copying %%~dpnxa
      echo copy /y "%%~dpnxa" "%destination%\%%~nxb_%%~nxa" >nul
   )
)
exit /b



NOTE: I have only added a single line of code here while redirecting COPY's output to the NUL device.

NOTE: This does NOT perform a pre-scan of the drive.

(see my next comment...)
 
0
t0t0Commented:
Oops! Re-posted due to a slight error. Pleas eignore my proevious comment. See this one instead.


A true progress indicator would rely on an initial pre-scan of the entire drive taking note of the number of files that need to be copied. Better indicators rely on file sizes too.

A simple indication might just display the names of each file as they're being copied such as in the following code:


@echo off
setlocal enabledelayedexpansion

set source=c:\
set filetype=*.ps9
set destination=z:\test

for /r "%source%" %%a in ("%filetype%") do (
   set folder=%%~pda
   set folder=!folder:~0,-1!
   for /d %%b in ("!folder!") do (
      echo Copying %%~dpnxa
      copy /y "%%~dpnxa" "%destination%\%%~nxb_%%~nxa" >nul
   )
)
exit /b



NOTE: I have only added a single line of code here while redirecting COPY's output to the NUL device.

NOTE: This does NOT perform a pre-scan of the drive.

(see my next comment...)
0
t0t0Commented:
I will add to this at a later time.....
0
t0t0Commented:
Oops! I'm in the process of clearing out some old stuff and realised I still need to reply to this one. Aplogies, and I will respond very shortly...
0
t0t0Commented:
I feel there is more I would like to add to this question.

Firstly though, my comment 28387579 provides code which performs the required task as well as displaying progress indication - which is that the asker wanted.

Also, the asker supplied code in his comment 28499706 which is a pile of rubbish. I have confirmed his code does not work syntactically nore logically yet, the asker is adament it does. There is obviously an issue here which I would like to explore further.

I was not able to contribute to this question since my last comment due to lack of time however, it has been my intention to reply with further assistance as well as establishing why the asker's code (so say) works for him but not for me.
0
t0t0Commented:
I feel there is more I would like to add to this question.

Firstly though, my comment 28387579 provides code which performs the required task as well as displaying progress indication - which is that the asker wanted.

Also, the asker supplied code in his comment 28499706 which is a pile of rubbish. I have confirmed his code does not work syntactically nore logically yet, the asker is adament it does. There is obviously an issue here which I would like to explore further.

I was not able to contribute to this question since my last comment due to lack of time however, it has been my intention to reply with further assistance as well as establishing why the asker's code (so say) works for him but not for me.
0
teotwawkiAuthor Commented:
there is a reason that i needed to step away from this question. as i pointed out when i posted the "rubbish" that i found after about 30 minutes of searching, it actually worked. i began looking because i was still waiting for a response to this because it was kind of urgent (hence the 500 point reward). again, i also asked for something that would show copy progress and none of the original solution attempts from t0t0 offered that. weeks later after my project was already completed 100% successfully, the copy progress option was brought up again by me but i don't recall seeing the actual code to do it. Also, not a single PST file was missed as this was verified by each end user.

as the moderator stated, dustin loftis has answered this question and no one else objected to say that robocopy could not do this. i should have just accepted that answer in the beginning...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.