I wants to create a batch file with the following conditions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
akbarsha03
Posts: 7
Joined: 25 Apr 2013 09:55

I wants to create a batch file with the following conditions

#1 Post by akbarsha03 » 25 Apr 2013 09:59

I'm having one great challenge according to create a batch file. Here is my situation I'm having folder full of folders and files(note all the files are in ".apf" extension). I want to create a empty file with ".event" extension in each and every folder where the folder name and if one of the file name is same. The created ".event" extension file should be same as the folder name and file name where as same. Thanks in advance pls help me.

Example: "apple"->folder name
"orange.abf","pineapple.abf","apple.abf" -> file names inside apple folder

I've to check the folder name and file name where they are same. If same name found then I have create a empty file in the same name with ".event" as a extension.

As I found apple as a same name in folder name and also file name I have to create a empty file as "apple.event"
Last edited by akbarsha03 on 25 Apr 2013 10:09, edited 1 time in total.

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: I wants to create a batch file with the following condit

#2 Post by Endoro » 25 Apr 2013 10:03

One of the file name is same of what?

akbarsha03
Posts: 7
Joined: 25 Apr 2013 09:55

Re: I wants to create a batch file with the following condit

#3 Post by akbarsha03 » 25 Apr 2013 10:12

I have briefly explained the condition please check. Thanks in advance

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: I wants to create a batch file with the following condit

#4 Post by Endoro » 25 Apr 2013 10:32

Try this and remove the "echo" command before "copy" if the output is OK:

Code: Select all

@echo off&setlocal 
set "startfolder=X:\my start\folder"
for /d /r "%startfolder%" %%i in (*) do if exist "%%~fi\%%~ni.apf" echo copy nul "%%~fi\%%~ni.event"

akbarsha03
Posts: 7
Joined: 25 Apr 2013 09:55

Re: I wants to create a batch file with the following condit

#5 Post by akbarsha03 » 25 Apr 2013 11:00

Endoro wrote:Try this and remove the "echo" command before "copy" if the output is OK:

Code: Select all

@echo off&setlocal 
set "startfolder=X:\my start\folder"
for /d /r "%startfolder%" %%i in (*) do if exist "%%~fi\%%~ni.apf" echo copy nul "%%~fi\%%~ni.event"


Thanks for the quick response and help.... Very much appreciated.. code worked once i removed the echo before copy!! thanks very much. May I know if i will give the location of the folder in shared path of the server, then it will work? If not what is the alternative?

:D :D

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: I wants to create a batch file with the following condit

#6 Post by Endoro » 25 Apr 2013 11:10

It should also work with a shared net ressource.

akbarsha03
Posts: 7
Joined: 25 Apr 2013 09:55

Re: I wants to create a batch file with the following condit

#7 Post by akbarsha03 » 25 Apr 2013 11:32

Endoro wrote:It should also work with a shared net ressource.



thanks for the guide :D :D .. One more small request. I dont know what the code is doing? could you please tell me? how the code works? step by step

thanks in advance

Post Reply