0

I'm using the forfiles command to list files and folders (included sub folders) which is piped to a text file. My subsequent process requires this output to be in comma delimited format (.csv).

This is the script I'm currently using and would like to update:

forfiles /s /C "cmd /c echo @file @fdate @ftime @isdir" > MyTextOutput.txt

Is it possible to send the output from the forfiles command to a .csv file?

3
  • well, put quotes around each field, a comma between each , and a newline at the end of a record. then after export, just rename the file to have a .csv extension. Nov 3, 2015 at 13:51
  • I'm sorry I don't follow?
    – RobN
    Nov 3, 2015 at 13:53
  • CSV is a text file, where each field (@file, @fdate, etc) is seperated by a comma (hence comma seperated value), and each record is delimited by a newline character. use quotes around each feild in case they contain a comma. saving a text document with these characteristics makes it a CSV, even if the file extension is differant. that means that once export is complete, you can just rename MyTextOutput.txt to MyTextOutput.csv. Nov 3, 2015 at 13:56

1 Answer 1

3

Try this:

forfiles /s /C "cmd /c echo @file, @fdate, @ftime, @isdir" > MyTextOutput.csv

You are telling the OS what to output, just tell it to output commas too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .