Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
on7june
- Posts: 2
- Joined: 04 Jan 2016 01:57
#1
Post
by on7june » 04 Jan 2016 02:31
I need to loop through a folder (FolderA) for each file we need to check a Lookup folder (LKPFldr) if the file doesn't exist then the current file from FolderA should be copied to this lookup folder LKPFldr and also to another folder called processFldr. These steps should be performed for each file in FolderA. I am trying to write a script as below,
Code: Select all
For /R FolderA %F in (*.xml)
DO
SET FileName=%~nF.xml
SET FullPath=%%i
For /R LKPFldr %F in (*.xml)
DO
SET LkpFldrPath= "Retrieve path alone"
IF EXISTS FileName
(REM - Do Nothing)
ELSE
( Copy FullPath LkpFldrPath
Copy FullPath processFldr )
I am not sure how to exclude file name with extension from full path. Also let me know if this approach is correct or do we have a better solution. Thank you.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 04 Jan 2016 02:39
Ignoring the myriad of syntax errors in your code for the moment - you are using a recursive switch in the initial for command, but haven't stated that you need to recurse through any directory tree.
Can you clarify the task a little further?
-
on7june
- Posts: 2
- Joined: 04 Jan 2016 01:57
#3
Post
by on7june » 04 Jan 2016 03:02
Apologies for my knowledge in writing scripts since I am new to windows scripting. The scenario is we have a folder in remote server where 10 files will be dropped in for every one hour. Currently we have process which will copy the files through FTP and load in to our local folder. From this local folder We need to process the file only once for this reason we are having a lookup folder and processing folder. First file from our local folder will check if this file exists in lookup if it doesn't find then the file is copied to this look up folder and process folder. Our job process the files present inside process folder, once completion its archived. After this second file will be checked against lookup folder and the process continues.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 04 Jan 2016 07:53
on7june wrote:Apologies for my knowledge in writing scripts since I am new to windows scripting.
You can look at the help for any command by typing a
/? after the command. This will show you the correct syntax for the commands you are trying to use.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#5
Post
by foxidrive » 05 Jan 2016 03:09
on7june wrote:Apologies for my knowledge in writing scripts since I am new to windows scripting.
It does seem as though you are new to Windows scripting. I would hazard a further guess that you are new to scripting and that this is a task you have for an assignment for class.
I make that comment because if you had knowledge in another language, then what you showed would have been a great deal closer to the actual task - which is around three lines.
Somehow you have made it recursive, and used two loops - where knowledge of another language would have made you realise that it was a mish-mash of commands.
I think you made it a mish-mash on purpose to get someone to do your assignment for you.
Many people do that these days.I'm old and cranky - and get even more cranky when people ask for free help and then tell porky-pies about their task.
See here:
viewtopic.php?f=3&t=6108