creating an list.txt imports also an Non-Printable char

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
imagination
Posts: 13
Joined: 24 May 2014 01:32

creating an list.txt imports also an Non-Printable char

#1 Post by imagination » 24 May 2014 01:37

Goodmorning all,

I am having some troubles with the following code

Code: Select all

@echo off
REM HERE WE ARE Making the List.txt that contains all the files that will be patched with the Patcher.
set LOCAL_RESCLIENT_DIR=e:\folder\Resclient
CD %LOCAL_RESCLIENT_DIR%
setlocal EnableDelayedExpansion
echo Ver:24 >%LOCAL_RESCLIENT_DIR%\list.txt
echo C:\\RESCLIENT>>%LOCAL_RESCLIENT_DIR%\list.txt
REM echo. >>%LOCAL_RESCLIENT_DIR%\list.txt
set "base=%CD%"
set "base=%base:*:=%\"

for /R %%a in (*.*) do (
   for /F "tokens=1-5 delims=/-. " %%b in ("%%~Ta") do set "dateTime=%%d-%%c-%%b  %%e%%f"
   set size=                   %%~Za
   set name= %%~PNXa
   echo !dateTime! !size:~-10! !name:%base%=!>>!LOCAL_RESCLIENT_DIR!\list.txt
)


What it does is creating an list.txt that has the following text in it

Code: Select all

2014-05-23  16:47          0  file.a
2014-05-24  09:27         63  list.txt


etc...
Its in an specific format cause the file will be read from an c++ program.
Now when i open the c++ program i get an error that the file is not found. This is due the fact that the Batch file
is adding an Non Printable character (DLE)(Data link Escape) ASCII 016

Could someone explain to me why this is happening?

With kind regards

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: creating an list.txt imports also an Non-Printable char

#2 Post by foxidrive » 24 May 2014 01:44

Where is it adding an ASCII character 16?

At the end of the file? Middle? Start?

imagination
Posts: 13
Joined: 24 May 2014 01:32

Re: creating an list.txt imports also an Non-Printable char

#3 Post by imagination » 24 May 2014 01:58

When i am calling the program that is reading the list.txt its adding it here

Image

Before the forward slash is the DLE character

Also when i am using an c++ program to make the list i dont have any problems.
So the problem lies with the batch file.

Dragokas
Posts: 43
Joined: 30 Jul 2013 09:42
Location: Ukraine, USSR
Contact:

Re: creating an list.txt imports also an Non-Printable char

#4 Post by Dragokas » 24 May 2014 06:12

Hi, imagination !

I can't reproduce your problem.
Try to save your batch file with Windows notepad.
If still nothing, please, give here a link to your log-file.

Best wishes, Alex.


foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: creating an list.txt imports also an Non-Printable char

#6 Post by foxidrive » 24 May 2014 09:13

The patcher folder could have a character at the of the foldername.

You haven't shown if it is in every line.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: creating an list.txt imports also an Non-Printable char

#7 Post by penpen » 24 May 2014 13:58

It's not easy to help you, when the error seems to be not reproducible:
Maybe you could describe your environment and write a minimalistic c++ program that produces the error.
The batch code you showed above does not produce a DLE character itself,
so it may be caused by the interaction of cpp program and log file.

But i'm not sure that your log file does not contain this character because your file contains this line:

Code: Select all

2014-05-24  09:27         63  list.txt
If I'm not mistaken, then it should be 62 bytes long as it should contain (piror adding this line):

Code: Select all

Ver:24 
C:\\RESCLIENT
2014-05-24  21:15          0  file.a
(+\r\n == 0X0D, 0x0A on each line). Does it contain the DLE
So how do you start the batch file?

Side note: It depends on how your cpp program handles it, but the wrong size of the file list.txt possibly could cause errors.

As you are using .gz files and the '/' character is your directory separator, i could imagine multiple other possible causes of errors;
batch file produced on win pc environment, interpreted using a unix/linux like environment:
- codepage issue,
- carriage return (CR == 0x0D) characters could cause problems,
- network folders could vary with real folder names,
- short vs long names,
- ...

penpen

imagination
Posts: 13
Joined: 24 May 2014 01:32

Re: creating an list.txt imports also an Non-Printable char

#8 Post by imagination » 24 May 2014 14:23

Thank you all for your answers.

I have solved the problem after 2 days.

It was really stupid
In my Batch file i have this

Code: Select all

echo C:\\RESCLIENT>>%LOCAL_RESCLIENT_DIR%\list.txt

this produces in the list .txt this

C:\\RESCLIENT (this should be done like so cause the c++ program change the \\ to /

So i did now this

Code: Select all

echo  C:\\RESCLIENT>>%LOCAL_RESCLIENT_DIR%\list.txt


Pay attention to the extra space between echo and the path name
That stupid space did the trick.

Again thank you all.

Btw i dont know if i can ask another question here or that i should open up an new Topic. If so then an Mod can alter it.

My following question is as follow
I am looking for an Batch script that can compare 2 files in 2 different folders by datetime and if folder/files have higher Modified date then the files inside Folder2 then goto MATCH
this is an quick example and its not working ofcourse


Code: Select all

FOR /R e:\folder1 %%A IN (*.*) DO (
    set filedatetime=%%~tA
    FOR /R e:\folder2 %%B IN (*.res.gz) DO (
        set filedatetime2==%%~tB
    )
    IF %filedatetime:~0, 10% == %filedatetime2:~0, 10% GOTO MATCH
    GOTO NOMATCH
)

:MATCH
echo Do Something

:NOMATCH
echo Do something else

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: creating an list.txt imports also an Non-Printable char

#9 Post by penpen » 24 May 2014 15:07

imagination wrote:So i did now this

Code: Select all

echo  C:\\RESCLIENT>>%LOCAL_RESCLIENT_DIR%\list.txt


Pay attention to the extra space between echo and the path name
That stupid space did the trick.
So i guess this is the byte difference between what the batch code above produces and your (partial) OP log file content (log.txt: 63 bytes) produced by (i assume it) a c++ program mentioned here:
Also when i am using an c++ program to make the list i dont have any problems.
So the problem lies with the batch file.
If you would have posted it (Edit: it == log.txt) completely, then it would have been easier to find the problem.

imagination wrote:My following question is as follow
I am looking for an Batch script that can compare 2 files in 2 different folders by datetime and if folder/files have higher Modified date then the files inside Folder2 then goto MATCH
(...)
If they are on the same local volume, then you may temporarily move them to a single folder (using move command) and compare it there using

Code: Select all

dir /T:W /O:D (...)
(...) for additional switches and arguments.
(I don't have tested it, but i doubt that it works on non local volumes, like network volumes.)

Else i assume you have to use an external program, as the filetime resulution of batch is very coarse:

Code: Select all

Z:\>@for %a in (*.txt) do @echo %~ta
24.05.2014 23:05
24.05.2014 23:05
24.05.2014 23:05
24.05.2014 23:05
24.05.2014 23:06
24.05.2014 23:06
24.05.2014 23:06

Brinda has programmed such a tool in ansi c:
http://www.dostips.com/forum/viewtopic.php?p=27618#p27618

penpen
Last edited by penpen on 25 May 2014 01:16, edited 1 time in total.

imagination
Posts: 13
Joined: 24 May 2014 01:32

Re: creating an list.txt imports also an Non-Printable char

#10 Post by imagination » 24 May 2014 15:47

If you would have posted it completely, then it would have been easier to find the problem.


I cant show the source of the c++ file cause i dont have access to the source. So then youre right its like searching for an needle in an haystack.

About the comparison both folders are at the same drive but this can change in the future
For example atm both are located on e:\ But some can put the original non zipped files on c:\Originalfolders and the zipped(.gz) files on e:\Gzipfolder

I dont wish to work with moving cause i am speaking in about 4GB of data that needs to be moved.

I have stumbled upon this code

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Build Original File array with modification dates
for /R e:\test %%f in (*.*) do (
   set originalFile["%%f"]="%%~Tf"
)

rem Process latest files and build New Or Modified list
set newOrMod=
for /R e:\Pandoraflyff\Resclient %%f in (*.*) do (
   if defined originalFile["%%f"] (
      if !originalFile["%%f"]! neq "%%~Tf" (
         rem File is modified
         set newOrMod=!newOrMod! "%%f"
      )
   ) else (
      rem File is new
      set newOrMod=!newOrMod! "%%f"
   )
)
rem Process New Or Modified file list in any way you wish, i.e.
for %%f in (%newOrMod%) do echo %%~ff>>New.tmp


It looks it did the trick for part of it
Cause i have now an tmp file with this in it

e:\Pandoraflyff\Resclient\Flyff.a
e:\Pandoraflyff\Resclient\list.txt
e:\Pandoraflyff\Resclient\Neuz.exe
e:\Pandoraflyff\Resclient\Pandora_00.res

So that means those files are Newer then the files in the other dir.
But here it comes

For gzipping i am using this code


Code: Select all

REM Gzipping
for /f %%A in (e:\Pandoraflyff\Batch\New.tmp) do (
   REM echo %%A
   e:\Pandoraflyff\Batch\Program\Gzip.exe -9 -k -c %%A > e:\test\%%A.gz
)


The problem with this code is that inside New.tmp the full path lies
e:\Pandoraflyff\Resclient\Flyff.a

So gzip isnt taking it cause this e:\test\e:\Pandoraflyff\Resclient\Flyff.a cant be done.
So is there an way of making it like so
Flyff.a

And if its in an dir
folder\flyff.a
subdir
folder\subfolder\flyff.a

With kind regards.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: creating an list.txt imports also an Non-Printable char

#11 Post by penpen » 25 May 2014 02:11

imagination wrote:
If you would have posted it completely, then it would have been easier to find the problem.


I cant show the source of the c++ file cause i dont have access to the source. So then youre right its like searching for an needle in an haystack.
I meant the logfile ("log.txt"), that size is 1 byte bigger on your OP than it could have been, if it were created with the batch code in your OP.
(But that's no problem anymore, as you have found the difference.)


imagination wrote:I have stumbled upon this code

Code: Select all

(...)
   set originalFile["%%f"]="%%~Tf"
(...)
      if !originalFile["%%f"]! neq "%%~Tf" (
         rem File is modified
(...)
      )
   ) else (
      rem File is new
(...)
   )
)

It looks it did the trick for part of it

This is true:

Code: Select all

!originalFile["%%f"]!   !=   "%%~Tf"   ==>   File is modified
But this is false (as i've written in my above post the batch filetime resolution is very coarse):

Code: Select all

!originalFile["%%f"]!   ==   "%%~Tf"   ==>   File is new
If you change the file within one minute, then it has been changed, but is reported as new.
For such a diferentiation, you need a much more finer granularity of the filetime resolution: See my above post (and read Brindas post linked there -> cpp source of what you need).



imagination wrote:But here it comes

For gzipping i am using this code

Code: Select all

REM Gzipping
for /f %%A in (e:\Pandoraflyff\Batch\New.tmp) do (
   REM echo %%A
   e:\Pandoraflyff\Batch\Program\Gzip.exe -9 -k -c %%A > e:\test\%%A.gz
)


The problem with this code is that inside New.tmp the full path lies
e:\Pandoraflyff\Resclient\Flyff.a

So gzip isnt taking it cause this e:\test\e:\Pandoraflyff\Resclient\Flyff.a cant be done.
So is there an way of making it like so
Flyff.a
It's not gzip, that doesn't like it, its the command line parser that doesn't like redirections like that ("> file" part); gzip will never se it.
So you have to change the for-loop variable modofier in the redirecting part;
you may list all possible For loop variable modifiers by entering "for /?" (without doublequotes) in the cmd shell.
I think you are looking for:

Code: Select all

e:\Pandoraflyff\Batch\Program\Gzip.exe -9 -k -c %%A > "e:\test\%%nxA.gz"
Sidenote: You should use doublequotes around filenames, as they may contain spaces.


imagination wrote:And if its in an dir
folder\flyff.a
subdir
folder\subfolder\flyff.a
I'm not sure how to understand these, but maybe you mean this:

Code: Select all

rem one for line per example above (only use the line you need)
for /f %%A in (folder\flyff.a\flyff.a) do (
for /f %%A in (subdir\flyff.a) do (
for /f %%A in (folder\subfolder\flyff.a\flyff.a) do (

penpen

imagination
Posts: 13
Joined: 24 May 2014 01:32

Re: creating an list.txt imports also an Non-Printable char

#12 Post by imagination » 25 May 2014 05:04

Well in fact it does take longer then 1 minute to change an file.
So with the %%~TA it should work

As for the folders i think the Gzip command you provided should be enough.

I will do some testing and will let you know about it.

Post Reply