Page 1 of 1

file Filename exist in folders

Posted: 24 Aug 2009 21:55
by anu
i have 3 folders.
ex: F1= c:\test\achieved\abcde_fghij_v1_2008_11_28120753.xml
F2=d:\test\error\abcde_fghij_v1.xml
F3=d:\test\resolved\
I need look for the file F2 exists in F1. Actually file F2 name is changed as F1+datetime values.

for this case actually the file exists. so move the file f2 to F3 folder

Posted: 25 Aug 2009 09:17
by avery_larry
**untested**

Code: Select all

@echo off
set "F1=c:\test\achieved"
set "F2=c:\test\error"
set "F3=c:\test\resolved"

for /f "tokens=*" %%a in ('dir /b /a-d "%F2%\*.xml"') do (
   dir "%F1%\%%~na*" >nul 2>nul
   if not errorlevel 1 move "%F2%\%%~a" "%F3%
)

Posted: 25 Aug 2009 20:55
by anu
thanks a lot . Really i never wrote any batch script before. can u please explain in detail.

I tested the script. whatever xml file starts with a it moved to resolved folder. but my requirement is

ex:

error folder consist of file abcde_fghij_v1.xml , asssss_ttttt_v1.xml,
ajjjj_fuuuuuuuu_v1.xml

achieved folder conists of abcde_fghij_v1_2008_11_28120753.xml ,aghjjjk_hjkiyt_v1.xml, ajjjj_fuuuuuuuu_v1_2009_11_28120753.xml

it should move only
abcde_fghij_v1.xml ,ajjjj_fuuuuuuuu_v1.xml
to resolved folder.

waiting for your reply.
thanks

Posted: 26 Aug 2009 09:36
by avery_larry
I tested it on my computer, and other than needing a double quote after "%F3% (which doesn't make the script fail), it worked just like I understood you wanted.

Code: Select all

@echo off 
set "F1=c:\test\achieved"
set "F2=c:\test\error"
set "F3=c:\test\resolved"

for /f "tokens=*" %%a in ('dir /b /a-d "%F2%\*.xml"') do (
   dir "%F1%\%%~na*" >nul 2>nul
   if not errorlevel 1 move "%F2%\%%~a" "%F3%"
)
Now, if error folder has:

asssss_ttttt_v1.xml

AND achieved folder has the SAME file, then the script doesn't work.

Posted: 26 Aug 2009 22:03
by anu
Thanks a lot. It works. May i know which is the code do the comparison of the file names.

if the file doesn't exist in the archieve. write it into the txt file.

for ex:asssss_ttttt_v1.xml doesnt exist in archieve. so it remains in error folder itself.
So need to generate a txt called FileNotExist.txt and write the file names.
if i open the txt file it shows asssss_ttttt_v1.xml does not exist in archieve

Posted: 27 Aug 2009 11:56
by avery_larry
Once you're done, a simple:

dir c:\error\*.xml

should do the trick. Redirect to a file

dir c:\error\*.xml > filenotexist.txt

Posted: 07 Sep 2009 20:25
by anu
sorry for the late reply. Thanks a lot. It works well.

Posted: 17 Sep 2009 03:37
by anu
Right now i am using the codes for my requirement
@echo off
set "F1=c:\test\achieved"
set "F2=c:\test\error"
set "F3=c:\test\resolved"

for /f "tokens=*" %%a in ('dir /b /a-d "%F2%\*.xml"') do (
dir "%F1%\%%~na*" >nul 2>nul
if not errorlevel 1 move "%F2%\%%~a" "%F3%"

)


for /f "tokens=*" %%a in ('dir /b "%F2%\*.xml"') do (
echo File not exists in Archieve %%a >> c:\test\log\fileNotExist.txt

)

but instead of using 2 for loops how to modify the code
* if the xml file not exist write into the fileNotExist.txt

Once come out from the for loop need to check if anything written into the txt file. if nothing is there need to delete the fileNotExist.txt file.

Posted: 17 Sep 2009 09:15
by avery_larry
Perhaps like this:

*UNTESTED*

Code: Select all

@echo off 
set "F1=c:\test\achieved"
set "F2=c:\test\error"
set "F3=c:\test\resolved"
set "errorlog=c:\test\log\fileNotExist.txt"
del "%errorlog%" >nul 2>nul

for /f "tokens=*" %%a in ('dir /b /a-d "%F2%\*.xml"') do (
   dir "%F1%\%%~na*" >nul 2>nul
   if not errorlevel 1 (
      move "%F2%\%%~a" "%F3%"
      ) else (
         echo The file %%~a does not exist in Achieved.>>"%errorlog%"
   )
)
if exist "%errorlog%" echo There were errors.  Check %errorlog%

Posted: 21 Sep 2009 19:49
by anu
i modified the below codes and works.

@echo off
set "F1=c:\test\achieved"
set "F2=c:\test\error"
set "F3=c:\test\resolved"
set "F4=c:\test\error\backup"
del "%errorlog%" >nul 2>nul

for /f "tokens=*" %%a in ('dir /b /a-d "%F2%\*.xml"') do (
dir "%F1%\%%~na*" >nul 2>nul
if not errorlevel 1 (
move "%F2%\%%~a" "%F3%"
) else (
echo File not exists in Archieve %%a >> c:\test\log\fileNotExist.txt
)
)

==============================
if there is any subfolders inside the error also need to check same logic.
For Ex :
inside c:\test\error there are 2 folders
backup1, backup2

need to verify the xml files in the backup1, backup2 compare with archieve folder . if not exist need to include it in fileNotExist.txt file.

Please help.thks

Posted: 22 Sep 2009 10:52
by avery_larry
Just change F1, F2, F3, F4 and re-run the script?

Posted: 22 Sep 2009 20:42
by anu
hi,
I have xml files likethis in error folder called control files.
O_A_20081121.XML,O_B_20081121.XML,O_A_20081121.XML.

Ex O_A_20081121.XML contain likethis

<?xml version="1.0" encoding="UTF-8"?>
<XA>
<Header>
<Total_Record_Count>2</Total_Record_Count>
</Header>
<XTable>
<XARecord>
<X_File_Name>abcde_fghij_v1.xml</XBRL_File_Name>
<XFiling_Dttm>20081120091132</XFiling_Dttm>
</XRecord>
</XTable>
<XTable>
<XARecord>
<X_File_Name>asssss_ttttt_v1.xml</XBRL_File_Name>
<XFiling_Dttm>20091120091132</XFiling_Dttm>
</XRecord>
</XTable>
</XA>

I need to read the control file and check abcde_fghij_v1.xml,
asssss_ttttt_v1.xml exists in archieve folder. If both the files exist move the control file to resolved. otherwise keep the control file in the error folder itself.

How to read the control file and how to find the filename ? But filename always in this tag <X_File_Name>asssss_ttttt_v1.xml</XBRL_File_Name>