

InterviewSolution
Saved Bookmarks
1. |
Solve : Organizing files by filename into separate folders? |
Answer» <html><body><p>Any help on this issue would be greatly appreciated. I have been running 100s of tests on a <a href="https://interviewquestions.tuteehub.com/tag/product-25523" style="font-weight:bold;" target="_blank" title="Click to know more about PRODUCT">PRODUCT</a> and the results end up in one folder.<br/><br/>The results are stored with the <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a> name Test_Report["Part <a href="https://interviewquestions.tuteehub.com/tag/number-238005" style="font-weight:bold;" target="_blank" title="Click to know more about NUMBER">NUMBER</a>"]["Time of test"]["Date of test"].html<br/><br/>I want to make a batch file that will organize the reports by part number into folders labeled with the part number and date. The part numbers range from 6 numbers to a combination of letters, symbols and numbers up to 15 characters long. <br/><br/>If you can help that would be awesome.is there any characters Part Number,Time of test, and Date of test<br/><br/><br/>ex <br/>Part Number-Time of test-Date of testJust those brackets<br/><br/>An example would be:<br/><br/>Test_Report[53010N0-10SD-00][6 15 11 AM][7 1 2010].htmlWill there ever be report files which have the same part number but different dates?<br/>Yes that is possible, so the batch file will have to look at both the date and part number to <a href="https://interviewquestions.tuteehub.com/tag/sort-238033" style="font-weight:bold;" target="_blank" title="Click to know more about SORT">SORT</a> it properly. I hadn't thought of that, thanks for bringing it to my attentionSo if these files existed<br/><br/>Test_Report[53010N0-10SD-00][6 15 11 AM][7 1 2010].html<br/><br/>Test_Report[53010N0-10SD-00][6 15 11 AM][6 30 2010].html<br/><br/>You would want them in 2 separate folders, called<br/><br/>53010N0-10SD-00 7 1 2010<br/><br/>and<br/><br/>53010N0-10SD-00 6 30 2010<br/><br/>is that right?<br/><br/>Any padding ( e.g. m d yyyy to mm dd yyyy) or desires about white space (e.g. convert to dashes?)<br/><br/>Yes that is exactly what I want. The same formatting of the date is fine. Maybe the date can be inside brackets to not get confused with the part number Code: <a>[Select]</a>echo off<br/>setlocal enabledelayedexpansion<br/>for /f "delims=" %%A in ('dir /b Test_Report[*.html') do (<br/> set filename=%%A<br/> for /f "tokens=1-4 delims=[]" %%B in ("!filename!") do (<br/> set FolderName=%%C (%%E^)<br/> if not exist "!FolderName!" md "!FolderName!"<br/> move "!filename!" "!foldername!"<br/> )<br/> )<br/>echo All files processed <br/>pause<br/><br/> Thank you so much! It <a href="https://interviewquestions.tuteehub.com/tag/workedralvaja-3284364" style="font-weight:bold;" target="_blank" title="Click to know more about WORKED">WORKED</a> like a charm. You just saved me from manually sorting through 500+ files</p></body></html> | |