Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: XCopy folders with relative paths!  (Read 15525 times)

0 Members and 1 Guest are viewing this topic.

soncu

  • Guest
XCopy folders with relative paths!
« on: July 06, 2006, 04:06:56 AM »
Hi All

I would like to copy folders recursively from one location to another. The problem is that the folder names are changing slightly, but it retains something unique all the time. Below is an example of what the folders look like:

Copy:
\\server\path\10.200.10.777_Unique_name_lang\Something_else

-the numbers in front of the _Unique_name are changing all the time

Paste:
\\server\path\Test

I'm trying to automate this and I was wondering if it can be done using batch programming. Any help would be greatly appreciated!  ;)

Soncu

GuruGary



    Adviser
    Re: XCopy folders with relative paths!
    « Reply #1 on: July 07, 2006, 12:21:31 AM »
    Please post the details on what part(s) of the path are static, and which part(s) change.  The more details we have the better we can help you script a solution.

    soncu

    • Guest
    Re: XCopy folders with relative paths!
    « Reply #2 on: July 07, 2006, 04:07:25 AM »
    Sorry I was a bit too evasive!

    Here is the explanation in detail:

    Path to copy:

    \\server\path\10.200.10.777_Unique_name_lang\Something_else

    10.200.10.777 - only these numbers change
    _Unique_name_lang\Something_else  - this is static

    Copy the above path to:

    \\server\path\Test

    I hope this is clear enough! Thanks for the help!

    Soncu    :)
    « Last Edit: July 07, 2006, 04:10:30 AM by soncu »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: XCopy folders with relative paths!
    « Reply #3 on: July 07, 2006, 05:33:46 AM »
    It would be possible to use wildcards, provided the nonstatic data keeps the same format:

    Example:
    Code: [Select]
    xcopy \\server\path\10.???.??.???_Unique_name_lang\Something_else \\server\path\Test  /s /e

    You can wildcard as much or as little of the nonstatic data as you need.

    Note: Suggest you use the ? wildcard instead of *. Less likely to run into problems.

     8-)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    soncu

    • Guest
    Re: XCopy folders with relative paths!
    « Reply #4 on: July 11, 2006, 09:42:22 AM »
    Sorry guys, your suggestion didn't seem to work. I'm using Windows XP Pro version. Any other suggestions?

    "xcopy \\server\path\10.???.??.???_Unique_name_lang\Something_else \\server\path\Test  /s /e"

    Here is the code I have:

    echo off
    set sourcedirMSI=K:\lang\10.0.1245.7777_Unique_name_lang\Something_else\file.txt
    set sourcedirCAB=K:\lang\10.0.1245.7777_Unique_name_lang\Something_else\file.xml
    set backupdir=C:\Test
    for /f "tokens=*" %%a in ('dir "%sourcedirMSI%" "%sourcedirCAB%" /s/b') do (
        xcopy "%%a" "%backupdir%%%~pa" /s/e
    )
    eof

    The scenario is like this: The numbers in front are variables, they change often, so I want to find every folder that has _Unique_name_lang and file.txt/xml in it and copy it to  C:\Test. At the moment I can only do a search in the lang folder for file.txt/xml, but this returns these files from all the folder and I only need the ones that contain _Unique_name_lang. I hope this makes sense!

    Thanks
    Soncu   :)
    « Last Edit: July 11, 2006, 10:24:22 AM by soncu »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: XCopy folders with relative paths!
    « Reply #5 on: July 11, 2006, 10:33:28 AM »
    I must be missing something. I thought the numbers kept changing, but based on your code:
    Quote
    set sourcedirMSI=K:\lang\10.0.1245.7777_Unique_name_lang\Something_else\file.txt
    they are set in stone. Would you not need to use the wildcards in the DIR command to create a collection of files or directories for the XCOPY to operate on?

    Like I said, maybe I'm missing something. :-?
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    soncu

    • Guest
    Re: XCopy folders with relative paths!
    « Reply #6 on: July 11, 2006, 10:42:00 AM »
    Sorry Sidewinder, you're right! From that example it looks like is a set path! I just wanted to show how the folder looks with the full path. My humble apologies. Indeed, those numbers are changing. I need something like a wildcard or anything that would ignore those numbers and look only at what's after it _Unique_name_lang\Something_else\file.txt, copies only file.txt, including the dirs it come from too, into C:\test.. I hope I'm not getting more confusing...

    Thanks
    Soncu
    « Last Edit: July 11, 2006, 10:42:18 AM by soncu »

    DosItHelp



      Intermediate
      Re: XCopy folders with relative paths!
      « Reply #7 on: July 11, 2006, 09:55:09 PM »
      How about this:

      Code: [Select]
      set sourcedirMSI=Something_else\file.txt
      set sourcedirCAB=Something_else\file.xml
      set backupdir=C:\Test
      FOR /f "tokens=*" %%a in ('dir /ad /b \\server\path\*^|findstr _Unique_name_lang$') do (
          if exist "%%a.\%sourcedirMSI%" xcopy "%%a.\%sourcedirMSI%" "%backupdir%" /s /e
          if exist "%%a.\%sourcedirCAB%" xcopy "%%a.\%sourcedirMSI%" "%backupdir%" /s /e
      )

      DOS IT HELP?

      soncu

      • Guest
      Re: XCopy folders with relative paths!
      « Reply #8 on: July 12, 2006, 04:33:27 AM »
      Thanks for the help DOSItHelp but unfortunately your suggestion didn't work! Here is an example of the full path:

      \\server\path\10.0.1234.7777_Unique_name_lang\Something_else

      I need to bypass "10.0.1234.7777", read "_Unique_name_lang" and xcopy all the files with file.txt/xml found in all the subdirectories.

      Thanks,
      Soncu

      DosItHelp



        Intermediate
        Re: XCopy folders with relative paths!
        « Reply #9 on: July 12, 2006, 06:34:20 PM »
        How about this?

        Code: [Select]
        set backupdir=C:\Test
        FOR /f "tokens=*" %%a in ('dir /s /b \\server\path\*^|findstr _Unique_name_lang\\') do (
            if /i "%%~nxa"=="file.txt" xcopy "%%a" "%backupdir%" /s /e
            if /i "%%~nxa"=="file.xml" xcopy "%%a" "%backupdir%" /s /e
        )
        [highlight]; )[/highlight]
        « Last Edit: July 12, 2006, 06:35:15 PM by DosItHelp »

        soncu

        • Guest
        Re: XCopy folders with relative paths!
        « Reply #10 on: July 14, 2006, 03:44:32 AM »
        Hi DosItHelp

        That works fine, but it only copies the files in the C:\Test folder in the root. I need the directories recursively as well. The /s/e switches don't seem to work.

        Thanks again
        Soncu  :)
        « Last Edit: July 14, 2006, 08:52:48 AM by soncu »

        DosItHelp



          Intermediate
          Re: XCopy folders with relative paths!
          « Reply #11 on: July 14, 2006, 11:53:25 PM »
          How about this?

          Code: [Select]
          set backupdir=C:\Test
          FOR /f "tokens=*" %%a in ('dir /b /ad \\server\path\*^|findstr _Unique_name_lang$') do (
              xcopy "%%a.\file.txt?" "%backupdir%" /s/y
              xcopy "%%a.\file.xml?" "%backupdir%" /s/y
          )
          [highlight]; )[/highlight]
          « Last Edit: July 14, 2006, 11:54:44 PM by DosItHelp »

          soncu

          • Guest
          Re: XCopy folders with relative paths!
          « Reply #12 on: July 25, 2006, 02:56:07 AM »
          Thanks a lot DosItHelp! With a bit of tweaking it worked fine! How about making it to extract the files newer than 2 days without setting a fixed date!

          Cheers
          Soncu

           ;)

          DosItHelp



            Intermediate
            Re: XCopy folders with relative paths!
            « Reply #13 on: July 25, 2006, 09:22:15 PM »
            Soncu,
            This will be a little more tricky.   Try this:

            set TmpFile=%temp%.\%~n0.tmp
            type NUL>"%TmpFileList%"
            &REM makes sure tmpfile is empty

            set backupdir=C:\Test
            FOR /f "tokens=*" %%a in ('dir /b /ad \\server\path\*^|findstr _Unique_name_lang$') do (
                xcopy "%%a.\file.txt?" "%backupdir%" /s/y/L&REM L-option Displays files that would be copied
                xcopy "%%a.\file.xml?" "%backupdir%" /s/y/L&REM L-option Displays files that would be copied
            )>"%TmpFile%"

            SETLOCAL ENABLEDELAYEDEXPANSION
            set /a AgeInDays=2
            call:jdate tnow "%date%"&REM get today in julian days
            for /f "tokens=*" %%F in ("%TmpFile%") do (
                call:ftime tfile "%%F"&REM get file time in julian days
                set /a diff=tnow-tfile
                if !diff! LEQ %limit% xcopy "%%~F" "%backupdir%%%~F"
            )

            PAUSE
            GOTO:EOF
            :: Goto http://dostips.cmdtips.com/DtTipsDateTime.php
            :: Copy :ftime :jdate :date2jdate functions below here
            [/b]

            You will need to get the functions [highlight]:ftime[/highlight] [highlight]:jdate[/highlight] and [highlight]:date2jdate[/highlight] from:
            [highlight]http://dostips.cmdtips.com/DtTipsDateTime.php[/highlight]

            Hope this helps  ;D
            « Last Edit: July 25, 2006, 09:26:02 PM by DosItHelp »