| 1. |
Solve : XCopy folders with relative paths!? |
|
Answer» Hi All set sourcedirMSI=K:\lang\10.0.1245.7777_Unique_name_lang\Something_else\file.txtthey 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. :-?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 SoncuHow 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?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, SoncuHow 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]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 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]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 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 |
|