Delete files and not replace them.
Moderators: Dorian (MJT support), JRL
Delete files and not replace them.
Hi,
I've done a search resulting in my head is in a spin.
What I want to do is to search a partition for files with the same name, that is, in all the folders in the partition and not to replace them, i.e. simply delete the file.
The file is Blueprint.bak and its in RailWorks simulator program folders.
When a route is installed there is that file in a lot of the folders, if they are not removed the sim won't run.
I've tried a few things but I can't get anywhere really.
Looking at the commands I had a look at IfFileExists, due to my lack of knowledge in this area of computing I have not got anywhere.
Can anyone assist please.
Thanks in advance.
Ian
I've done a search resulting in my head is in a spin.
What I want to do is to search a partition for files with the same name, that is, in all the folders in the partition and not to replace them, i.e. simply delete the file.
The file is Blueprint.bak and its in RailWorks simulator program folders.
When a route is installed there is that file in a lot of the folders, if they are not removed the sim won't run.
I've tried a few things but I can't get anywhere really.
Looking at the commands I had a look at IfFileExists, due to my lack of knowledge in this area of computing I have not got anywhere.
Can anyone assist please.
Thanks in advance.
Ian
Many thanks
Ianw
Ianw
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Will this do you:
Code: Select all
Let>root=c:
Let>RP_WINDOWMODE=2
Let>RP_WAIT=1
Run>cmd /c dir "%root%\Blueprint.bak" /s /b > "%TEMP_DIR%~temp_dir_list~"
ReadFile>%TEMP_DIR%~temp_dir_list~,dir_list
Separate>dir_list,CRLF,files
If>files_count>0
Let>k=0
Repeat>k
Let>k=k+1
Let>this_file=files_%k%
DeleteFile>this_file
Until>k=files_count
Endif
Last edited by Marcus Tettmar on Thu Aug 27, 2009 11:08 am, edited 2 times in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Marcus,
I've tried your macro above but it does not work.
The macro is very, very fast, it has hardly started when it stops.
As the Blueprint.bak files are not deleted I'm thinking the macro may not be actually scanning the partition.
May I ask, in the first line :-
Let>root=c:\
Is it OK if I change the c to another drive letter, that is, e:
so that is will scan the E: partition.
Thanks for your help.
I've tried your macro above but it does not work.
The macro is very, very fast, it has hardly started when it stops.
As the Blueprint.bak files are not deleted I'm thinking the macro may not be actually scanning the partition.
May I ask, in the first line :-
Let>root=c:\
Is it OK if I change the c to another drive letter, that is, e:
so that is will scan the E: partition.
Thanks for your help.
Many thanks
Ianw
Ianw
Hi Ian.Is it OK if I change the c to another drive letter, that is, e:
so that is will scan the E: partition.
It is not only OK.... it is required that you change the letter in the "root" variable to the letter that relates to your partition. That is why Marcus placed the drive designation in a variable and put it at the top of the script where it can easily be found.
Hope this is helpful.
Thanks JRL, I did do that though the macro still does not work.
I ommited to inform that when I ran the macro there is a very short duration, a better description is a flash, of a message or something when I try to run the macro and that is the sum total of the macros activity.
I'm using MS v11 latest build.
I ommited to inform that when I ran the macro there is a very short duration, a better description is a flash, of a message or something when I try to run the macro and that is the sum total of the macros activity.
I'm using MS v11 latest build.
Many thanks
Ianw
Ianw
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
One thing I missed in my code was quotes - if any paths have spaces it would fail. Correct code:
If it still doesn't work please get analytical. Use the debugger. Step through it. What is the value of dir_list? What happens after the Separate? What is the value of files_count? Try the CMD manually. E.g. type the following in a CMD prompt:
dir e:\Blueprint.bak /s /b
What do you see? Does DOS produce a list of files?
Code: Select all
Let>root=c:
Let>RP_WINDOWMODE=2
Let>RP_WAIT=1
Run>cmd /c dir "%root%\Blueprint.bak" /s /b > "%TEMP_DIR%~temp_dir_list~"
ReadFile>%TEMP_DIR%~temp_dir_list~,dir_list
Separate>dir_list,CRLF,files
If>files_count>0
Let>k=0
Repeat>k
Let>k=k+1
Let>this_file=files_%k%
DeleteFile>this_file
Until>k=files_count
Endif
dir e:\Blueprint.bak /s /b
What do you see? Does DOS produce a list of files?
Last edited by Marcus Tettmar on Thu Aug 27, 2009 11:07 am, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
This is my first with the Debugger I hope I did it correctly.
I went into Edit, Debug, Run and Step.
------------------------------
ROOT=C:\
RP_WINDOWMODE=2
RP_WAIT=1
RP_RESULT=1
DIR_LIST= (no result on this one)
---------------------
Separate :-
FILES_Count=0
--------------------------------------
Try the CMD manually.
What do you see?
dir c:\Blueprint.bak /s /b = 4
Does DOS produce a list of files?
Yes it does.
There are a total of 4 files, 1 in each of 4 folders.
I tried it in E with 2 files and it found and listed them.
I hope that helps.
I went into Edit, Debug, Run and Step.
------------------------------
ROOT=C:\
RP_WINDOWMODE=2
RP_WAIT=1
RP_RESULT=1
DIR_LIST= (no result on this one)
---------------------
Separate :-
FILES_Count=0
--------------------------------------
Try the CMD manually.
What do you see?
dir c:\Blueprint.bak /s /b = 4
Does DOS produce a list of files?
Yes it does.
There are a total of 4 files, 1 in each of 4 folders.
I tried it in E with 2 files and it found and listed them.
I hope that helps.
Many thanks
Ianw
Ianw
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Try removing the trailing slash from the first line where you set up your root folder. I just realised it is adding another slash in the Run line. Perhaps both slashes cause an error for the DOS command. I'll update my post accordingly.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?