file Filename exist in folders
Moderator: DosItHelp
file Filename exist in folders
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
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
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
**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%
)
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
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
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
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.Now, if error folder has:
asssss_ttttt_v1.xml
AND achieved folder has the SAME file, then the script doesn't work.
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%"
)
asssss_ttttt_v1.xml
AND achieved folder has the SAME file, then the script doesn't work.
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
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
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
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.
@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.
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Perhaps like this:
*UNTESTED*
*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%
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
@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
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
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>
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>