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?

  • 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. – Frank Thomas Nov 3 '15 at 13:51
  • I'm sorry I don't follow? – BobJim Nov 3 '15 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. – Frank Thomas Nov 3 '15 at 13:56

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.