1.

Solve : getting the no.of files and file name from a folder?

Answer» HI All,

Am new to this forum and also new to DOS(not having more idea)

Here i have written a batch file to add header, root tag to the generated file and converting .csv into .xml and moving it to another folder

here is the code :

more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/header.xml > C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/root.xml >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data1/employee.csv >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/closeRoot.xml >> C:/gsk


it's working fine, but in that i have hard coded the input and output file names like input file employee.csv and output file employee.xml

instead of hard coding the those file names i would like to get dynamically, and also let me know how to take the count of messages in folder


Thanks in Advance


Note sure I fully understand the question

But here goes....

To output a list of all files in a folder to output.txt
dir /b c:\ | find "" /n /v >output.txt

To output a list of all files in a folder and all sub folders to output.txt
dir /b /s c:\ | find "" /n /v >output.txt


To make this more dynamic and not hard code it, instead of for EXAMPLE employee.csv, you can use %1
If you for example saved this as xml.bat then running this batch file in the command prompt with the parameter employee.csv will replace %1 with employee.csv
i.e
xml.bat employee.csv

if you use a second parameter, this would be %2 in the batch file

You could then create another batch file which calls xml.bat with all its parameters. If you need to change the files, you would only need to change this batch file.

Hope that helpsall i know is that to convert a file into another file copy the code below:

rename *.csv *.xml

The above will completely change your .csv into a .xml
but the only thing you MUST remember is that you must have this program in the same folder you wish to change those certain files to the other file type.

You can add the move .xml to another folder thing in when ever you want.

Do not replace the '*' with anything else just leave it how it is.

Tan_ZaHi Tan_Za

This requirement is not that much easy as you said

please go through my post again

Hi TheManFrom,

Thanks a lot for your reply, but here my problem is

one application is keep on generating the files with the date_time stamp, i cannot pass the file name as an argument, because the files always generates id different timestamp

and also i need to add the header, open root tag, close root tag to the each and every file

please help me on this, because totally am new to dos(am not having more commanding on dos)

Thanks in Adavance, Your Help is Appreciated

Save the following in c:\xml.bat

REM--------------------------------------
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/header.xml >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/root.xml >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data1/%1 >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/closeRoot.xml >> C:/gsk
REM--------------------------------------


Open notepad, copy and paste the script below and change the first line to point to your folder, then save as c:\xml.vbs

'------------------------------------------
CONST StrFolder = "C:\temp"
CONST StrBatch = "C:\xml.bat"

Set fsoFolder = CreateObject("Scripting.FileSystemObject")
Set folder = fsoFolder.GetFolder(StrFolder)

Set files = folder.Files

for each objFile in files
set shell=createobject("wscript.shell")
Shell.Run StrBatch & " " & objFile.Name, 0, True
set shell=nothing
next

set files = nothing
set folder = nothing
set fsoFolder = nothing
'------------------------------------------


open command prompt and type
cscript xml.vbs


This will now run the vbs script which will go and find all files in the folder you specified. It will then pass the name of the file to xml.bat, which will add the header, root etc and output as employee.xml
Note, this will keep writing to the same employee.xml file - you will need to amend the batch file to change this. You can change employee.xml to "%1.xml" to have the name of file read .xml

Hope thats what you neededNOTE: to list the files(s) in a directory (folder) simply type:


DIR [path[dir]]?

I do this all the time, to display files in a folder, when i boot my comp in DOS-Mode.

I have no idfea what all the extra code is for, but can't u simply type:

DIR [path]
rename [path][filename]??The original code has a CSV file processed by the more utility and producing a XML file. This is not gonna happen. Oh, it will run OK, but you'll still have a CSV file (just with a new and misleading name).

Code: [Select]more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/header.xml > C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/root.xml >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data1/employee.csv >> C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/data/employee.xml
more < C:/gskgaa_v3/gskgaa/common/UTC_6.8.6/Receiver1/post-processor/closeRoot.xml >> C:/gsk

Processing files thru the more utility does not change the organization of a file. NEITHER does copy, move or rename. A file extension acts much like the title of a book...it indicates what to expect when it's opened. Windows uses the file extension to call the proper application that can process each file type. Simply calling a CSV file a XML file does not make it so.

Quote
let me know how to take the count of messages in folder

Down and dirty this snippet should work:

Code: [Select]for /f %x in ('dir ^| find /i "file(s)"') do echo %x

Use the above code at the command prompt. To use in a batch file, double up the percent symbols.



Discussion

No Comment Found