file Filename exist in folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
anu
Posts: 8
Joined: 24 Aug 2009 21:18

file Filename exist in folders

#1 Post by anu » 24 Aug 2009 21:55

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 25 Aug 2009 09:17

**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%
)

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#3 Post by anu » 25 Aug 2009 20:55

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 26 Aug 2009 09:36

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.

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#5 Post by anu » 26 Aug 2009 22:03

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#6 Post by avery_larry » 27 Aug 2009 11:56

Once you're done, a simple:

dir c:\error\*.xml

should do the trick. Redirect to a file

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

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#7 Post by anu » 07 Sep 2009 20:25

sorry for the late reply. Thanks a lot. It works well.

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#8 Post by anu » 17 Sep 2009 03:37

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.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#9 Post by avery_larry » 17 Sep 2009 09:15

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%

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#10 Post by anu » 21 Sep 2009 19:49

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#11 Post by avery_larry » 22 Sep 2009 10:52

Just change F1, F2, F3, F4 and re-run the script?

anu
Posts: 8
Joined: 24 Aug 2009 21:18

#12 Post by anu » 22 Sep 2009 20:42

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>

Post Reply