1.

Solve : Loging error in TXT file - Please help?

Answer» HI,

Here is my code :

echo off
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul
mkdir "HIL02 - Hôtel XYZ Montréal\03 - Hôtel XYZMontréal - Banquet + Pâtisserie">>Logfile.txt 2>&1
chcp %cp%>nul

The error type will be recorded in the logfile.txt.  This works great.  The thing is that my actual file has over 11,000 entry to process.  Out of these, I have only 7 that doesn't work.  I get the error message just fine in the logfile, but I need to know which lines are the problem.

Is there a way to get that information somehow? In my logfile, for each error, I would like the problematic path name to be copied.

I already made research for characters such as ? / () # and these are taken out.  I have no clue where the problem lies.  I also check for path length (max 260 allowed) and I'm way under the limit even including the sub-folders created.

ThanksWhat is this code supposed to do?
It creates a bunch of folders and subfolders based on a list.  Each customer has a folder.  Then each each of their folders there is standard sub-folders.  This code, generates it all automatically.

There must be one in the bunch that has a bad character or something in it but I can't find it.  The logtxt file, logs it as a wrong path name, but I can't find which one because I have over 11000 lines to look at.What's with all the chcp stuff?It ALLOWS me to use french character such as é à You mean there are 11,000 lines like this?

mkdir "HIL02 - Hôtel XYZ Montréal\03 - Hôtel XYZMontréal - Banquet + Pâtisserie">>Logfile.txt 2>&1

Yes but with different information according to each customer.  It worked for them all except one.  So basically I need to find out which line cause the error.  This code tells me the error, but do not tell me which line doesn't work though.Why have you got the directory names in the batch file itself? Having 1000 lines makes it very cumbersome. Why don't you have them in a text file and read the lines using FOR /F? That way you have each line in a variable and you can isolate the problem lines.

Honestly, I'm building this as I go along by reading forums and multiple information posted.  I never programmed DOS before.  There is probably other solution, simpler maybe, but the problem remains that I need a log that explicitly says which line doesn't work.

Do you think that having the paths in another file will work?  Surely I will still need a line of code or something that program the batch file to export in a log file the information? Quote
mkdir "HIL02 - Hôtel XYZ Montréal\03 - Hôtel XYZMontréal - Banquet + Pâtisserie">>Logfile.txt 2>&1
Heck I want to know how much time you spent typing this out 11,000 times.  The problem may be a folder name with a character that isn't valid in your codepage.

Put all your folder names in a "c:\folder\file.txt" file and try the code below in an empty folder:

It may also SHOW folders that contain a character that is translated by the code page, so you may have
other folders in the errorlog.txt file.  You can manually check to see if those folders exist, if there are not too many of them.

At least that's how I understand codepages issues, as I don't often use non-latin characters.

Code: [Select]echo off
chcp 1252
(
   for /f "usebackq delims=" %%a in ("c:\folder\file.txt") do (
      md "%%a"
      if not exist "%%a\" echo error in line "%%a"
   )
)>"c:\folder\errorlog.txt"
echo done
pause
Quote from: Squashman on July 15, 2015, 02:53:44 PM
Heck I want to know how much time you spent typing this out 11,000 times.

Excel baby!  The information was exported from our ERP system in an excel file.  All I had to do is concatenate the cells to have what i wanted.  No typing to do at all.  Just copy/paste Quote from: foxidrive on July 16, 2015, 01:33:57 AM
The problem may be a folder name with a character that isn't valid in your codepage.

Put all your folder names in a "c:\folder\file.txt" file and try the code below in an empty folder:

It may also show folders that contain a character that is translated by the code page, so you may have
other folders in the errorlog.txt file.  You can manually check to see if those folders exist, if there are not too many of them.

At least that's how I understand codepages issues, as I don't often use non-latin characters.

Code: [Select]
echo off
chcp 1252
(
   for /f "usebackq delims=" %%a in ("c:\folder\file.txt") do (
      md "%%a"
      if not exist "%%a\" echo error in line "%%a"
   )
)>"c:\folder\errorlog.txt"
echo done
pause

This is very close.  The only problem is that it doesn't follow the folder structure requested; it creates folders for each word and characters instead.  I tried your code with mkdir and I get the same problem.

There is a minor tweaking to do i'm GUESSING to make it work.

*** Update : I found my mistake.  In my file with the information to create folders, all paths were between "".  I removed it.  Also I had to change md to mkdir.  Works like a charm!  It showed me the exact 7 lines that had a problem.  I fixed it and now I have 14178 folders & subfolders or subfolders created automatically in about 30 seconds!

Thank you so much for your help!I'm pleased to hear it helped you.

Just adding here that md and mkdir do exactly the same thing in Windows.


Try these two:

Code: [Select]md "123"
mkdir "456"


Discussion

No Comment Found