All,
I have written a batch file to loop through a directory, but only retrieve and copy files with names that contain the strig 'APR_DATA'. TO get the listing, I use *APR_DATA*.txt, as the string is in the middle of the file name. When I run it, however, it appears to return all of the files in the directory. THe wildcards work from just a regular DOS command line. Here is the text of my batch file. Any ideas why it's not working?
for /f "\\win2kdevfs1\sharedfolders$\FTP\LOAD\APR_DRG\" %%i IN (*APR_DATA*.txt) DO call :moveit %%i
:moveit
IF NOT EXIST '\\dwbaseline\ETLSourceFiles\FlatFiles\Test\%1' COPY \\win2kdevfs1\sharedfolders$\FTP\LOAD\APR_DRG\%1 \\dwbaseline\ETLSourceFiles\FlatFiles\Test\%1
Need Wildcard help
Moderator: DosItHelp
Re: Need Wildcard help
Code: Select all
pushd "\\win2kdevfs1\sharedfolders$\FTP\LOAD\APR_DRG\"
for %%i IN (*APR_DATA*.txt) DO call :moveit %%i
:moveit
IF NOT EXIST '\\dwbaseline\ETLSourceFiles\FlatFiles\Test\%1' COPY \\win2kdevfs1\sharedfolders$\FTP\LOAD\APR_DRG\%1 \\dwbaseline\ETLSourceFiles\FlatFiles\Test\%1
I don't see any reason to call another label in this instance.
Code: Select all
pushd "\\win2kdevfs1\sharedfolders$\FTP\LOAD\APR_DRG\"
for %%i IN (*APR_DATA*.txt) DO (
IF NOT EXIST "\\dwbaseline\ETLSourceFiles\FlatFiles\Test\%%i" COPY "%%I" \\dwbaseline\ETLSourceFiles\FlatFiles\Test\
)
-
- Posts: 2
- Joined: 01 Feb 2012 16:32
Re: Need Wildcard help
That seems to work. Thanks! I am still confused as to why the wildcard didn't work. The original code I used copied the files, it just didn't filter them the way I wanted.
One other question though: If I run this from a command line (instead of double-clicking in Windows Explorer), it changes the directory. There there any way to avoid that? Or to return to the original directory where it was executed?
One other question though: If I run this from a command line (instead of double-clicking in Windows Explorer), it changes the directory. There there any way to avoid that? Or to return to the original directory where it was executed?
Re: Need Wildcard help
Sorry that's my fault. Put the POPD command at the end of the batch file.