Jump to content

unix shell script to DOS translation


Recommended Posts

Hi there,

 

Does anyone know how the following script could be amended to work in dos?

 

Cheers

 

TOP_DIR=$1

count=1

for FILE in `find $TOP_DIR -type f -print`

do

        mv $FILE $FILE.$count

        count=`expr $count + 1`

done

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

I don't know Unix shell scripting at all, but I'm taking a rough guess and hoping that that's supposed to count the number of files in the root directory.  If not, let me know and I'll revise my batch file for you.  If I'm right in my assumption, here's your Windows batch file equivalent:

 

dir /a "C:\" |find /c /v ""

 

Now, that will only count the number of files in the root directory.  It won't look inside any subdirectories.  Add the /s switch after the /a to search inside subdirectories.

 

If you were trying to make a batch file that asks the user were to search, you could use something like:

 

::File count
::captbeagle
CLS
@ECHO OFF
title Counting your files... one by one!
SET /P directory=Directory to search:
SET /P sub=Search subdirectories [Y/N]:
IF "sub"=="Y" GOTO subs
GOTO no_subs

:subs
dir /a /s %directory% |find /c /v ""
pause
exit

:no_subs
dir /a %directory% |find /c /v ""
pause
exit

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.