move_all.btm

Apr 2, 2011
1,442
10
54
North Carolina, USA
I have the following snippet of code:

Code:
 :DoFldr
    rem for each file in this fldr
    rem   compare extension to each s* variable abouve
    rem     if match is fouind = move file to folder named above - depending on type of file....
    rem     else move to C:\Z_NewAll\z_NewDown\

    echo ``
    echo Processing %_CWD

    for %fn in (*) (
      echos .
      IFF isfile "%fn" then
        set pTGT=%sUnkn%
        set cExt=%@upper[%@ext["%fn"]]

The problem is that %fn can have chars that setdos /x..... would help process correctly, but I don't want to use setdos at all but want to iterate over all those badly named files. Is there a way to do this? At the very least I thought the IFF isfile "%fn" then .... ELSE ... ENDIFF would help trap those files....
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Charles Dye's SafeChars.dll plug-in should be able to assist in processing your ill-named files.

I cannot scroll below the line starting with set scExt. Is this intentional?

Suggest you use do / enddo instead of multiline command group with FOR - there have been many reasons listed in the Forum. Also it is my guess that switch would be a a simpler method for selecting between multiple enumerated alternatives than iff/elseiff/elseiff/else.
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
I said it was just a snippet - not full statements. But just for grins I'll post the full BTM here as an attachment.
 

Attachments

  • Move_All.btm
    11.1 KB · Views: 88
May 20, 2008
3,515
4
Elkridge, MD, USA
Request help from its author... The issue about which I defer to Charles Dye is that while safechars provides a unique mapping for the special characters into "nonspecials", for the MOVE command ultimately you need the reverse translation as well, and I am not at this time prepared to do so.
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
All I want to do is to leave the files that have special chars or that would if isfile "%fn" ... would generate an error.....

Will contact the author shortly.... thanks S.F.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
Which characters are you having trouble with?

Double-quoting the filename will help with some problem characters (spaces, ampersands.) You can deal with the escape character easily enough by remapping it to something weird, e.g. SETDOS /E0XFFF8. But if your filenames contain grave accents ("backquotes") or percent signs, you're pretty much out of luck. I don't think SafeChars will help with such filenames; sorry....

I do have a plugin FixNames that looks for some of the most egregiously awful filenames (graves, percent signs, carets, and so on) and attempts to rename them. You don't get much control over the new filenames, though. In most cases, the problem characters are just replaced with underscores.
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Charles, I guess the best way to find out the chars I am having trouple with is to do:

[path] dir /a:-d /b /s /f * > outfile.lst

remove the full path of each file in outfile.lst, leaving just the full name.

then remove chars I know not to cause problems, namely, 0-9,A-F,a-f then the punctuation chars.

upload the file ......

Am I correct?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Actually, PDIR is your friend here:
[path]pdir /a:-d /s /(fn) > outfile.lst
which gives you the whole list without path names.
One could then take the whole file, and read it character by character (beware of Unicode vs. ASCII), e.g., using @filereadb or @bread, and mark those characters which occur in the file. The result will be which characters occur...
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Would I need to turn Unicode on before the PDIR?

So use a loop to @filereadb or @bread then write to a new file one char per line then sort and remove duplicates?
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
and I guess Unicode needs to be on when I create the 2nd output file? Will create and send the file later tonioght - going out for dinnere now...
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Using this short BTM to create the 2nd file, and UNICODE is ON

Code:
goto :here

outfile_unicode.lst created with unicode ON and PDIR command earlier in message thread.

:here
set h=%@fileopen[outfile_Unicode.lst,r]
set o=%@fileopen[outfile_out.lst,write]
do forever
  set b=%@filereadb[%h,1]
  if "%b" EQ **EOF** LEAVE
  set z=%@filewrite[%o,%b]
  echos .
enddo
echo closing handle #%h: %@fileclose[%h]
echo closing handle #%o: %@fileclose[%o]
 
May 20, 2008
3,515
4
Elkridge, MD, USA
More like this:
Code:
:here
setarray codes[65536]
set h=%@fileopen[outfile_Unicode.lst,r]
set n=%@fileseek[%h,0,2]
do while %@fileseek[%h,0,1] LT %n
  set uc=%@filereadb[%h,2]
  set codes[%uc]=1
enddo
echo closing handle #%h: %@fileclose[%h]

Now all Unicodes used are set to 1, unused Unicodes are undefined. The next step is to find those Unicodes which are not "nice" to have in filenames...
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
The next step would be to go thru codes[] and write out the index for entries that are set to TRUE?

then from there see what are not good items for filenames?

Thank you for your help!!!
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Code:
setlocal

  timer on
  set cOutFile=c:\z_Unicode\Out\outfile_unicode.lst

  goto :here

  set Unicode=%@option[UnicodeOutput]
  option //UnicodeOutput=Yes
  pdir /a:-d /s /(fn) c:\Z_NewAll\* c:\Z_UserFiles\* >! %cOutFile
  option //UnicodeOutput=%Unicode

  :here
  unsetarray /q codes
    setarray    codes[65536]
  for /l %nIndex in (0,1,65535) set codes[%nIndex]=0
  set h=%@fileopen[%cOutFile,r]
  echo File handle: %h
  set n=%@fileseek[%h,0,2]
  echo File Size: %@comma[%n]
  set nAt=0
  set n=%@fileseek[%h,0,0]
  do while %@fileseek[%h,0,1] LT %n
    set uc=%@filereadb[%h,2]
    set nAt=%@inc[%nAt]
    set nAt=%@inc[%nAt]
    set codes[%uc]=1
  enddo
  echo closing handle #%h: %@fileclose[%h]
  echo Reads: %@comma[%nAt]

  rem for /l %nIndex in (0,1,65535] if codes[%nIndex] EQ 1 echo %@format[5,%nIndex]

  timer off

endlocal

Gives:

Code:
[C:\Program Files\JPSoft\TCMD16x64]c:\z_Unicode\WriteFile.btm
Timer 1 on: 16:34:01
File handle: 520
File Size: 6,988,998
closing handle #520: 0
Reads: 0
Timer 1 off: 16:34:04  Elapsed: 0:00:02.96

I don't know about fileread or fileseek so why is it not going inside the DO WHILE .... ENDDO
 
May 20, 2008
3,515
4
Elkridge, MD, USA
A comment: it is not necessary to initialize the array. The value of each element is either 1 or it is not.
I made a mistake which you caught - I should just have used @filesize. This would be the correct logic:

echo File handle: %h
set n=%@filesize[%cOutFile]
echo File Size: %@comma[%n]
set nAt=0
do while %@fileseek[%h,0,1] LT %n
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Steve,

%uc is 2 numbers, yet codes array is one column. What needs to happen. It gives correct output except for the set codes[%uc]=1
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
I ended up:

echo [%uc] >>! aOutputFile
sort aOutputFile /output aOutputFile.out
remove duplicate lines in aOutputFile.out

Now what do I need to do?
 

Attachments

  • outfile_codes.txt
    2.1 KB · Views: 81
May 20, 2008
3,515
4
Elkridge, MD, USA
Apparently the data is little-endian, as is typical of the Intel-like architectures. The sort itself is based on the decimal representation of the low order digit being more significant than the high order. One of your alternatives is to just postprocess the listing and sort them in true numeric order; the other is to rebuild the list as numeric.

I am just writing a postprocessing program for the data you collected to display it in a more reasonable order.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
OK, I massaged your data with the following BTM:
Code:
@echo off
setlocal
do l in @c:\work\cg\codes.txt
  set nobrkt=%@trim[%@strip[[],%l]]
  set high=%@word[1,%nobrkt]
  set low=%@word[0,%nobrkt]
  set num=%@eval[ 256 * %high + %low ]
  echo %@fz3[%high] %@fz3[%low] %@f6[%num] %@fz4[%@convert[10,16,%num]]   %l
enddo

(fz3=%@format[03,%&] and f6=%@format[6,%&])

The BTM puts in leading zeros as needed, puts the high order byte before the low order byte, and adds both decimal and hexadecimal columns. Probably the hexadecimal column will be the most meaningful.
 

Attachments

  • fixed.txt
    6.8 KB · Views: 92
Apr 2, 2011
1,442
10
54
North Carolina, USA
Steve,

What is next please? Remember this work is just to see what chars in the orginal list TCMD/TCC has problems with - so that the file names can be changed...
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Here is the redirected output and error files for Fixnames /N /S * in both directories....
 

Attachments

  • fixnames.zip
    12.2 KB · Views: 84

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
Most of your problem filenames seem to have carets. Easy enough to deal with by temporarily changing your escape character, e.g. SETDOS /E0XFFFE. One contains backquotes, which are harder to deal with. (Try an external like FIXNAMES, or run REM in a transient CMD.EXE shell?)

And one just contains some 0xFF characters -- not illegal and not really a problem at all, just potentially confusing if you happen to use one of those code pages where it's a non-breaking space.
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Code:
[C:\Z_UserFiles]mode

Status for device CON:
----------------------
    Lines:          5000
    Columns:        188
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      437


[C:\Z_UserFiles]
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
Code:
setlocal

  timer on

  set cOutFile=c:\z_Unicode\Out\outfile_unicode.txt

  set cCodesFile=c:\z_Unicode\Out\outfile_codes.txt

  set cSortedFile=c:\z_Unicode\Out\outfile_Sorted.txt

  set cSortedUnique=c:\z_Unicode\Out\outfile_Sorted.txt.unq

  set cFinalFile=c:\z_Unicode\Out\FinalFile.txt

  del /q /n:e /w %cOutFile %cCodesFile %cSortedFile %cFinalFile

  echo Making PDIR list....

  set Unicode=%@option[UnicodeOutput]
  option //UnicodeOutput=Yes
  pdir /a:-d /s /(fn) c:\Z_NewAll\* c:\Z_UserFiles\* >! %cOutFile
  option //UnicodeOutput=%Unicode

  :here

  echo Reading Unicode chars from list file...

  set h=%@fileopen[%cOutFile,r]
  echo File handle: %h
  set nSize=%@filesize[%cOutFile]
  echo File Size: %@comma[%nSize]
  set nAt=0
  do while %@fileseek[%h,0,1] LT %nSize
    set uc=%@filereadb[%h,2]
    set nAt=%@inc[%nAt]
    set nAt=%@inc[%nAt]
    echo [%uc] >>! %cCodesFile
  enddo
  echo closing handle #%h: %@fileclose[%h]
  echo Reads: %@comma[%nAt]

  del /q /n:e /w "%cOutFile"

  rem for /l %nIndex in (0,1,65535] if codes[%nIndex] EQ 1 echo %@format[5,%nIndex]

  rem =================================================================================

  echo SORTing Unicode codes file

  sort %cCodesFile /Output %cSortedFile

  del /q /n:e /w "%cCodesFile"

  echo Loading MEW32

  rem Next line creates "%cSortedUnique"
  start /pgm mew32 /snSorted "%cSortedfile"

  del /q /n:e /w "%cSortedFile"

  rem =================================================================================

  :Here1

  echo making Final File.....

  do l in @%cSortedUnique
    set nobrkt=%@trim[%@strip[[],%l]]
    set high=%@word[1,%nobrkt]
    set low=%@word[0,%nobrkt]
    set num=%@eval[ 256 * %high + %low ]
    echo %@format[03,%high] %@format[03,%low] %@format[6,%num] %@format[04,%@convert[10,16,%num]]   %l >>! %cFinalFile
  enddo

  del /q /n:e /w "%cSortedUnique"

  echo Final file: %cFinalFile

  timer off

endlocal

gives the attached results.

How can I see the actual chars in the %cFinalFile?
 

Attachments

  • FinalFile.txt
    6.7 KB · Views: 77
May 20, 2008
3,515
4
Elkridge, MD, USA
Use the @char[] function for each entry. You can modify my little program (after :Here1) by inserting "%@char[%num]" before the %l.

The program attached does the whole job, but has not been tested.
 

Attachments

  • COMBINED.BTM
    961 bytes · Views: 83
Similar threads
Thread starter Title Forum Replies Date
C question re: Move Support 3
samintz MOVE and Prompt on overwrite Support 3
M MOVE does not behaves like intended (on failure) Support 1
kb6ojs Make /G parameter persistent in COPY/MOVE command? Support 4
F Regexes in REN/MOVE/… commands seem to not work at all Support 3
T How to? Off screen move? Support 3
fpefpe Documentation copy/move using /c or /u Support 2
W Recursive move aborts early Support 2
C b21 MOVE /B Support 8
D How move cursor out of popup edit control after no match? Support 14
nickles Move takecommand.18.0.key location to installation directory Support 4
J junction copy/move handling Support 6
J WAD move /s regression from tcc15 Support 5
C move /F Support 4
vefatica MOVE anomaly Support 8
C Move /s sorce target Support 13
Stefano Piccardi b32 move /Q writes message Support 1
C How to? MOVE and handling out of space Support 2
Joe Caverly How to? Move Window Between Monitors Support 6
S How to? Move files older than one year Support 9
fpefpe move /g Support 4
C Move /MD not always working Support 1
C Move question with Encrypted file... Support 6
W /g option (%) on MOVE cmd appears broken TCC 14.03.57 x64 Support 8
G Fixed MOVE truncates files Support 9
C MOVE making empty destinatation sub-folders Support 10
thedave Move files, inherit permissions Support 14
A Discrepancy in handling of "can't copy or move file to itself" Support 4
A expected behavior of move /sx Support 14
S MOVE from FTP directory to another FTP directory - bug?? Support 2
J directory tree - move or copy Support 3
D MOVE Help typo Support 3
D Suggest Help mention /n no effect in move /n Dir1 Dir2 Support 0
D Move /v to DVD fails but files identical Support 4
S Conditionally MOVE/COPY files on the basis of size Support 1
S MOVE to different drive Support 3
Joe Caverly Move Buttons Between Tabbed Toolbars Support 2
S Another 4NT 8.02 vs TCC 9.02 diff - MOVE command Support 3
S MOVE command over FTP with 4NT 5.00U Support 0
MickeyF equivalent to TCSTART.btm for TCMD? Support 4
vefatica Console not redrawn in BTM or with multiple commands Support 4
Joe Caverly Embedding an .EXE (or other file) into a .BTM Support 8
Charles S. Roaten Problems with TCSTART.BTM Support 1
P Kill all other instances of tcc from a btm batch file Support 2
C TCC 26 BATCOMP BTM problems? Support 5
B IF command problem in tcexit.btm Support 9
vefatica WAD DIR.BTM? Support 11
vefatica BTM, elevated, console window caption? Support 4
I BTM slower than BAT? Support 14
D btm file command line augments comparing for string or math. Support 12

Similar threads