Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:07:18+00:00 2026-06-04T20:07:18+00:00

I have a bat file to process all file under a directory, and output

  • 0

I have a bat file to process all file under a directory, and output to another directory

this is the codes in the bat file

@set dir1=mulit-simp\
@set dir2=mulit-trad\
@cd /d %~dp0
@if not exist %dir1% md %dir1%
@if not exist %dir2% md %dir2%
@for /f "delims=" %%i in ('dir %dir1%*.* /b') do @opencc.exe --input="%dir1%%%i" --output="%dir2%%%i"
@echo.
@echo Done!
@echo.
@pause

but this code can’t process files in the sub directory
How could I process the sub directory files, and output them with the same directory structure to another directory?
thx for help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:07:19+00:00Added an answer on June 4, 2026 at 8:07 pm

    The DIR /S option would give you the entire folder hierarchy. And you also want the /A-D option to suppress folders from the output. Type HELP DIR or DIR /? for more info.

    However, instead of using FOR /F with DIR, I recommend using FOR /R. Type HELP FOR or FOR /? for more info. Also see http://judago.webs.com/batchforloops.htm for easier to understand explanation of the FOR command.

    Either way, you also need to create all of the destination folders. The easiest way to do that is to use XCOPY /T /E to create the destination folders prior to processing the files.

    Some additional tips:

    • Simply put @echo off at the top instead of prefixing every command with @
    • ECHO. has been widely used for years, but it can actually fail to work properly. Safer to use ECHO( instead.
    • You probably don’t want the environment variable you define to hang around after the batch is finished. Putting SETLOCAL at the top will make the variables temporary and they will exist only until the batch file finishes, or until ENDLOCAL is executed. Given that you are using PAUSE at the end, I suspect you are running the batch file by double clicking on the file or a shortcut. If so, then the command window closes at the end, and the variables disappear along with it. Then SETLOCAL is not needed, but it is still probably a good practice to get into anyway.

    Here is the finished code with all of the suggestions. EDIT – The original code did not work. Altered to address tiance’s comments

    @echo off
    setlocal
    set dir1=mulit-simp
    set dir2=mulit-trad
    cd "%~dp0"
    
    :: Replicate tree
    if not exist "%dir1%" md "%dir1%"
    if not exist "%dir2%" md "%dir2%"
    xcopy /t /e "%dir1%" "%dir2%"
    
    :: Get length of absolute path of %dir1%
    <nul set /p "=%cd%\%dir1%" >getLength.tmp
    for %%F in (getLength.tmp) do set len=%%~zF
    del getLength.tmp
    
    :: Process the files
    for /r "%dir1%" %%F in (*) do (
      set "src=%%F"
      setlocal enableDelayedExpansion
      opencc.exe --input="!src!" --output="%dir2%!src:~%len%!"
      endlocal
    )
    echo(
    echo Done!
    echo(
    pause
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have bat-file, that make some operations. How to run this file from Delphi
I have bat file like below with name myBat.bat 1) @echo off set CLASSPATH=%CLASSPATH%;C:\Documents
I have created a .bat file that displays all the users logged in Windows
I have this BAT file iARP.BAT Content Begin @ECHO OFF npg -vv -f %1
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have a powershell command running when I execute a bat file, The command
I have scrip contain command line: set dir=%1 cd %dir% test.bat echo successful When
I have created a .bat file that displays a servers terminal Service SessionID and
How to make .BAT file delete it self after completion? I have a simple
Possible Duplicate: .Net Process.Start default directory? I have a C# application, mono to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.