bfuchs
asked on
Code to delete contents of all files
Hi Experts,
I'm looking for either code or script that will do the following
loop thru all files of specific folder, not including sub folders (folder should only contain CSV files).
delete all the contents of those files, but do not delete the file itself.
Thanks
I'm looking for either code or script that will do the following
loop thru all files of specific folder, not including sub folders (folder should only contain CSV files).
delete all the contents of those files, but do not delete the file itself.
Thanks
ASKER
Hi,
Need to remove headers as well.
See screenshot.
Thanks,
Ben
Untitled.png
Need to remove headers as well.
what if just deleting the files and recreate them with new files with empty content?That may work, as long the name of files are exactly the same.
See screenshot.
Thanks,
Ben
Untitled.png
what about deleting the file and then creating a 0 byte file with the same name?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Experts,
@Ryan,
Will test it tom at work.
Thanks,
Ben
what about deleting the file and then creating a 0 byte file with the same name?As mentioned, this should be fine.
@Ryan,
Will test it tom at work.
Thanks,
Ben
You should be able to do this command right from a DOS command prompt to empty the files, just adjust the folder name as needed.
»bp
for %A in ("c:\temp\*.csv") do @echo.>"%~A"
And if you truly want a 0 byte file (rather than an empty text file) then you could do:for %A in ("c:\temp\*.csv") do @copy /y NUL "%A">NUL
»bp
ASKER
Hi Experts,
Tested and both work, great!
Now one question if you dont mind...
Since I constantly need to check for date/time they were created.
and with the utility above its something difficult (see attached).
would it be possible to
a- retain the file originally created date
b- display that in explorer, instead of date modified.
Thanks,
Ben
Untitled.png
Tested and both work, great!
Now one question if you dont mind...
Since I constantly need to check for date/time they were created.
and with the utility above its something difficult (see attached).
would it be possible to
a- retain the file originally created date
b- display that in explorer, instead of date modified.
Thanks,
Ben
Untitled.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you my experts!
are those csv files contain the headers? do you want to remove or retain the headers when you "emptying" the file content?
what if just deleting the files and recreate them with new files with empty content?