delete a files with their name and path in another file .bat

Multi tool use
up vote
1
down vote
favorite
I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.
my_file.txt
file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789
The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).
Is it possible? Help me pls
Thanks.
batch-file batch-processing
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
favorite
I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.
my_file.txt
file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789
The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).
Is it possible? Help me pls
Thanks.
batch-file batch-processing
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
1
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.
my_file.txt
file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789
The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).
Is it possible? Help me pls
Thanks.
batch-file batch-processing
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.
my_file.txt
file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789
The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).
Is it possible? Help me pls
Thanks.
batch-file batch-processing
batch-file batch-processing
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 9 at 12:29
Gerhard Barnard
6,44731030
6,44731030
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 9 at 12:18
Mario33
82
82
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
1
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39
add a comment |
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
1
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
1
1
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You would run a for loop and split on the ,
delimeter and use each as a variable.
So as an untested example, here I will split the file entries and assign 2 tokens %%i
and %%j
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"
Note that I added a double quotes to the tokens as it will possibly contain spaces.
Seeing that you want to do a delete, it will probably be something like:
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"
Where you would just remove the echo to perform the actual delete.
As per your comment, to skip the first line and exclude the **rows affected
line you can use:
for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
alternatively seeing that you are using more, you can exclude skip=1
and simply use +1
on the mroe command.
for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with anotherfor /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
|
show 3 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You would run a for loop and split on the ,
delimeter and use each as a variable.
So as an untested example, here I will split the file entries and assign 2 tokens %%i
and %%j
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"
Note that I added a double quotes to the tokens as it will possibly contain spaces.
Seeing that you want to do a delete, it will probably be something like:
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"
Where you would just remove the echo to perform the actual delete.
As per your comment, to skip the first line and exclude the **rows affected
line you can use:
for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
alternatively seeing that you are using more, you can exclude skip=1
and simply use +1
on the mroe command.
for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with anotherfor /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
|
show 3 more comments
up vote
0
down vote
accepted
You would run a for loop and split on the ,
delimeter and use each as a variable.
So as an untested example, here I will split the file entries and assign 2 tokens %%i
and %%j
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"
Note that I added a double quotes to the tokens as it will possibly contain spaces.
Seeing that you want to do a delete, it will probably be something like:
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"
Where you would just remove the echo to perform the actual delete.
As per your comment, to skip the first line and exclude the **rows affected
line you can use:
for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
alternatively seeing that you are using more, you can exclude skip=1
and simply use +1
on the mroe command.
for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with anotherfor /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
|
show 3 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You would run a for loop and split on the ,
delimeter and use each as a variable.
So as an untested example, here I will split the file entries and assign 2 tokens %%i
and %%j
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"
Note that I added a double quotes to the tokens as it will possibly contain spaces.
Seeing that you want to do a delete, it will probably be something like:
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"
Where you would just remove the echo to perform the actual delete.
As per your comment, to skip the first line and exclude the **rows affected
line you can use:
for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
alternatively seeing that you are using more, you can exclude skip=1
and simply use +1
on the mroe command.
for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
You would run a for loop and split on the ,
delimeter and use each as a variable.
So as an untested example, here I will split the file entries and assign 2 tokens %%i
and %%j
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"
Note that I added a double quotes to the tokens as it will possibly contain spaces.
Seeing that you want to do a delete, it will probably be something like:
@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"
Where you would just remove the echo to perform the actual delete.
As per your comment, to skip the first line and exclude the **rows affected
line you can use:
for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
alternatively seeing that you are using more, you can exclude skip=1
and simply use +1
on the mroe command.
for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"
edited Nov 9 at 14:09
answered Nov 9 at 12:33
Gerhard Barnard
6,44731030
6,44731030
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with anotherfor /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
|
show 3 more comments
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with anotherfor /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52
You can strip off leading spaces with another
for /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
You can strip off leading spaces with another
for /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05
1
1
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44
|
show 3 more comments
Mario33 is a new contributor. Be nice, and check out our Code of Conduct.
Mario33 is a new contributor. Be nice, and check out our Code of Conduct.
Mario33 is a new contributor. Be nice, and check out our Code of Conduct.
Mario33 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225597%2fdelete-a-files-with-their-name-and-path-in-another-file-bat%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
XNQuPZCh,jhoD 0F494uY3M0RhT84 HLLLtv7 aC9M8T,GrbpQ1YYNt,chzHByIHGwSTb U,ER7aUnEivjEV,qoX Hk8dP
This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27
Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32
1
@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39