Page 1 of 2
Removing data/making empty - the list of files in a folder
Posted: 07 Jul 2014 03:31
by vsmeruga
Hi Gurus
I am looking for a windows command/procedure to remove the content (or) making the files empty - for a list of (.xls files only) in a folder.
Your help is much appreciated.
Many Thanks
VJ
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:05
by foxidrive
Run this in the folder with the xml files you want to destroy and it will make them into 0 byte files.
Code: Select all
@echo off
for %%a in (*.xml) do type nul >"%%a"
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:10
by vsmeruga
Thanks I will try.
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:21
by vsmeruga
I tried it locally on my machine and command worked. When I tried in shared folder, It is not working. It seems the existing .xls files has some security
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:30
by foxidrive
You need write permission to the files in the shared folder.
Be aware that the files can't be open in Excel or another program at the same time.
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:50
by vsmeruga
Hi Foxidrive
I am struggling to achieve it.
Before removing data from the list of files, Can you help me with a command to set write permissions to all the files(.xls) in a folder?
Thanks
VJ
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 04:57
by foxidrive
Your IT people can give you write permissions.
I don't know anything about the situation you are in.
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 05:14
by vsmeruga
sure thanks. I will talk to them
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 05:57
by vsmeruga
Hi Foxidrive
I managed setting the path with the command pushd "path" and it worked. But when I double click to open the file I am getting the message as
"Excel cannot open the file 'Filename.xlsx' because the format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file"
script:
Code: Select all
@setlocal enabledelayedexpansion
pushd \\filepath\AutoRec
for /f %%a in ('dir /b *.xlsx') do type nul >"%%a"
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 06:05
by vsmeruga
Hi
Do you have any other command to remove full content and saving the same file instead of outputting using (>)
Thanks
VJ
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 07:23
by vsmeruga
I am using MS office 2010.
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 07:38
by Squashman
So you are looking to remove the contents of a bunch of excel files but still have the excel file open with excel.
That would require some other scripting language like Vbscript or Jscript or even an excel VBA macro.
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 08:03
by Aacini
Just create an empty Excel document in advance and copy it with the name of the files you want to delete:
Code: Select all
@setlocal enabledelayedexpansion
pushd \\filepath\AutoRec
for %%a in (*.xlsx) do copy C:\thePath\EmptySheet.xlsx "%%a" /Y
Antonio
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 08:26
by Squashman
Aacini wrote:Just create an empty Excel document in advance and copy it with the name of the files you want to delete:
Code: Select all
@setlocal enabledelayedexpansion
pushd \\filepath\AutoRec
for %%a in (*.xlsx) do copy C:\thePath\EmptySheet.xlsx "%%a" /Y
Antonio
That would certainly keep it simple!
Re: Removing data/making empty - the list of files in a fold
Posted: 07 Jul 2014 09:02
by vsmeruga
Thanks. I managed this issue checking the size of the file. If filesize is Zero then do not process it.