Removing data/making empty - the list of files in a folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Removing data/making empty - the list of files in a folder

#1 Post by vsmeruga » 07 Jul 2014 03:31

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Removing data/making empty - the list of files in a fold

#2 Post by foxidrive » 07 Jul 2014 04:05

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"

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#3 Post by vsmeruga » 07 Jul 2014 04:10

Thanks I will try.

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#4 Post by vsmeruga » 07 Jul 2014 04:21

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Removing data/making empty - the list of files in a fold

#5 Post by foxidrive » 07 Jul 2014 04:30

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.

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#6 Post by vsmeruga » 07 Jul 2014 04:50

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Removing data/making empty - the list of files in a fold

#7 Post by foxidrive » 07 Jul 2014 04:57

Your IT people can give you write permissions.

I don't know anything about the situation you are in.

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#8 Post by vsmeruga » 07 Jul 2014 05:14

sure thanks. I will talk to them

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#9 Post by vsmeruga » 07 Jul 2014 05:57

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"

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#10 Post by vsmeruga » 07 Jul 2014 06:05

Hi

Do you have any other command to remove full content and saving the same file instead of outputting using (>)

Thanks
VJ

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#11 Post by vsmeruga » 07 Jul 2014 07:23

I am using MS office 2010.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Removing data/making empty - the list of files in a fold

#12 Post by Squashman » 07 Jul 2014 07:38

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.

Aacini
Expert
Posts: 1927
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Removing data/making empty - the list of files in a fold

#13 Post by Aacini » 07 Jul 2014 08:03

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Removing data/making empty - the list of files in a fold

#14 Post by Squashman » 07 Jul 2014 08:26

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!

vsmeruga
Posts: 35
Joined: 04 Jun 2014 06:42

Re: Removing data/making empty - the list of files in a fold

#15 Post by vsmeruga » 07 Jul 2014 09:02

Thanks. I managed this issue checking the size of the file. If filesize is Zero then do not process it.

Post Reply