I am trying to make a program that will gather some documents and data, rename them, encrypt them and store them on a removable disk. While I have found a way to gather the documents, and encrypt them, I have yet to determine how to rename all the documents. Preferably the name of the documents would be a randomly generated string.
My current code is as followed:
@echo off
color a
ipconfig > D:\DONOTDELETE\DONOTDELETE\ip.txt
net user > D:\DONOTDELETE\DONOTDELETE\users.txt
tasklist > D:\DONOTDELETE\DONOTDELETE\tasks.txt
systeminfo > D:\DONOTDELETE\DONOTDELETE\info.txt
driverquery > D:\DONOTDELETE\DONOTDELETE\drivers.txt
timeout 1
for %%F in ("%userprofile%\Documents\*") do certutil -encode "%%F" "D:\DONOTDELETE\DONOTDELETE\%%~nxF"
I am hoping to have the files copied from the Documents folder to be renamed such that they are a random string.
I'm trying to rename the files to a random string. My primary issue is I am an awful programmer, after about an hour of googling and searching through stack overflows, I was unable to find a solution to my problem.
Using the code suggested, I receive the following error.
ERROR REPORT-
DecodeFile returned The data is invalid. 0x8007000d
CertUtil -encode Command Failed: 0x8007000d
CertUtil The data is invalid.
I think this would be what you're trying to do:
@echo off
setlocal EnableDelayedExpansion
color a
ipconfig > D:\DONOTDELETE\DONOTDELETE\ip.txt
net user > D:\DONOTDELETE\DONOTDELETE\users.txt
tasklist > D:\DONOTDELETE\DONOTDELETE\tasks.txt
systeminfo > D:\DONOTDELETE\DONOTDELETE\info.txt
driverquery > D:\DONOTDELETE\DONOTDELETE\drivers.txt
timeout 1
for %%F in ("%userprofile%\Documents\*") do (
call :randomString newfilename 20
certutil -encode "%%F" "D:\DONOTDELETE\DONOTDELETE\!newfilename!%%~xF"
)
goto :eof
:randomString
set length=%2
set CHARS=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
echo %CHARS%>x&for %%? in (x) do set /a strlength=%%~z? - 2&del x
for /L %%a in (1 1 %length%) do (
set /a randnr=!random!%%!strlength!
for /l %%n in (!randnr! 1 !randnr!) do set "line=!line!!CHARS:~%%n,1!"
)
set %1=%line%
goto :eof
User contributions licensed under CC BY-SA 3.0