Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete files using wildcards

Posted on 2006-11-29
15
Medium Priority
?
374 Views
Last Modified: 2010-05-18
We redirect user's "My Doc's" folders to a file server via group policy.  Under the "My Doc's" folder, every user has another folder called "Scan Docs" which contains scanned pdf documents. I'm looking for a way to perform a weekly deletion of all .pdf's in each users "scan docs" folder located in their respective "my docs" folder.  The folder tree looks something like the following:

\\server1\rfolders$\username1\mydocs       - where "username1" is the users login id so each will be different.

I'm looking to run some type of batch delete command from server1.   - something like:

del g:\rfolder$\%username%\mydocs\*.pdf

But I can't get by the %username%

Any suggestions?

0
Comment
Question by:presstek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
15 Comments
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18041509
Have you tried using quotes? If the username contains a space, you will need it for sure. Might also want to use 'S' switch for subfolders, if any, and once tested 'Q' -quiet mode
del  /s  /q  "g:\rfolder$\%username%\mydocs\*.pdf
0
 

Author Comment

by:presstek
ID: 18048542
I keep receiving a  "path not found" error so I'm assuming the del command can't convert %username% into a user ID?
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18048741
I just tied it exactly as shown on both a local drive an a network drive without a problem.

Perhaps try and narrow down the problem just checking access first. Do the following work
dir g:
dir g:\rfolder$
dir g:\rfolder$\%username%
dir g:\rfolder$\%username%\mydocs\
dir g:\rfolder$\%username%\mydocs\*.pdf

By the way, you ave to be an admin to access a hidden share (i.e. share ending in '$'). Perhaps that is the problem
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:presstek
ID: 18070881
I am logged in as a domain admin.  I can get as far as rfolders$ but when I do a dir g:\rfolders$\%username% - OR - dir g:\rfolders$\%username%\mydocs, I receive a "The system can not find the file specified" error
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18071266
At a command line what does;
  set  username
return. Is it the correct value, i.e. name?
0
 

Author Comment

by:presstek
ID: 18071277
One additional comment:  I can only do a dir on a "%username% folder if I am logged in as THAT user.  It looks as if it only converts %username% as the current logged in user account.  This explains why I receive the "file not found" error if I am logged in as a user (domain admin) that does not have a user named folder.
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18071316
Absolutely. %username% is a variable created each time a user logs on. It is set for the duration of the session and matches the user logon name exactly (without the domain name)
0
 

Author Comment

by:presstek
ID: 18071401
Can you think of any other way to write a script/batch file that can delete data from "each" user directory without having to log in as every user?
0
 
LVL 77

Accepted Solution

by:
Rob Williams earned 500 total points
ID: 18073447
There are a lot of ways you can do this. How were you planning to implement. Were you going to manage and run for each user, use within the logon script, or another means. Usually when using the %username% variable, it is intended to be run by the user themselves, manually or within a logon script.

If you have numerous users and want to automate it I would download the free delold.exe utility from:
http://www.xs4all.nl/~chi/utilities/delold.html
Then extract the files to the default script location on the server:
C;\Windows\SYSVOL\sysvol\YourDomainName\scripts
This is shared as  \\ServerName\NETLOGON

Then add the following to the users logon scripts:
\\ServerName\Netlogon\DelOld.exe   /f=g:\rfolder$\%username%\mydocs\*.pdf   /d=7
This will delete any pdf files in the users folder that are older than 7 days, each time the user logs on.

------------------------------------------------------------------

If you wish to do it manually, as an admin, you can create a little batch file on your system such as:

::  Batch file to clean up pdfs
set name=%1
del g:\rfolder$\name\mydocs\*.pdf
exit

Save it as DelPDF.bat  Then to run just enter:    DelPdf  username
0
 

Author Comment

by:presstek
ID: 18077697
Thanks for the tip.  I'll download and test delold.exe  - I'll let you know how it goes
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18080769
There are ways with a batch file to run through a list of names/accounts and delete but that little utility makes it simpler. Good luck with it, and let us know how you make out.
--Rob
0
 

Author Comment

by:presstek
ID: 18123147
Rob...works quite well although the login script takes a while longer to run now that files are being deleted during logon...but I'll take it!

thx!
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18123540
Yes, I'm sure it would slow things down a bit. Glad to hear it works for your though.
Cheers !
--Rob
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question