Copy or Export Windows Files to Excel Per Column using Command Line

6,584

Use the .txt version as you described: dir > export.txt

Then, open Excel and from within excel open the file (Ctrl-O, or File/Open from the ribbon), making sure to set the Type to All Files (*.*). Don't open the file by dragging it from file explorer.

When you select the file from the File Open dialog box, Excel should respond by displaying the 'Text Import Wizard'. On this wizard, select Fixed width as the Original data type, and then click the Next button.

In step 2, the wizard should open a Data preview window which by default will put the output from the dir command into a columnar structure. It seems to get it mostly right, but puts the time of day indicator (AM/PM) into a separate column than the time itself.

enter image description here

Removing the separator between these two columns (merging them into 1 column) is done by double-clicking the arrow head at the top of the column line.

After clicking Next to proceed to stage 3 of the wizard, you'll want to ensure the first column has a data format of Date (DMY in my case, MDY in yours). Hit finish and the file list data should be imported with a separate column for date, time, whether the file is a directory, filesize, and filename.

Share:
6,584

Related videos on Youtube

rickyProgrammer
Author by

rickyProgrammer

Updated on September 18, 2022

Comments

  • rickyProgrammer
    rickyProgrammer almost 2 years

    I need to copy the whole content of Windows Files into Excel Document. Below is the example Image of the Windows Explorer containing the files to be exported

    enter image description here

    Using Command Prompt

    I do this line to copy the files but it is not copying or being exported per column

    dir > export.xls 
    

    I also tried exporting it first to .txt and just copy but still output

    dir > export.txt
    

    Here's the result

    enter image description here

    expected output is it to be exported per column.

    • Admin
      Admin over 7 years
      Just to clarify; do you want to important the content of the files into Excel or just the timestamps and filenames?
    • Admin
      Admin over 7 years
      not the content of each file, just the file name and other information such as size, date modified... in per column way, as you can see in what I have, i can export it but in one column all
    • Admin
      Admin over 7 years
      You might find that Powershell can do what you want for a directory, E.g dir | select-object PSChildName, FullName | export-csv -NoTypeInformation export.csv To see all the columns available: dir | export-csv exportraw.csv
  • rickyProgrammer
    rickyProgrammer over 7 years
    this works I have question though
  • mcalex
    mcalex over 7 years
    What's the question?
  • rickyProgrammer
    rickyProgrammer over 7 years
    put it in another question superuser.com/questions/1178997/…